home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / lang / asm / 523 < prev    next >
Encoding:
Internet Message Format  |  1992-12-31  |  1.1 KB

  1. Path: sparky!uunet!mcsun!sun4nl!cwi.nl!dik
  2. From: dik@cwi.nl (Dik T. Winter)
  3. Newsgroups: alt.lang.asm
  4. Subject: Re: looking for fast min()/max()
  5. Keywords: speed min max
  6. Message-ID: <8493@charon.cwi.nl>
  7. Date: 1 Jan 93 01:51:55 GMT
  8. References: <1992Dec30.152808.25311@netcom.com> <C04r9K.92o@mentor.cc.purdue.edu>
  9. Sender: news@cwi.nl
  10. Organization: CWI, Amsterdam
  11. Lines: 20
  12.  
  13. In article <C04r9K.92o@mentor.cc.purdue.edu> hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
  14.  > I do not know how fast this is, and it requires having an absolute value.
  15.  > The absolute value on 2's complement machines can be gotten around, but
  16.  > again, unless the sum and difference of the numbers do not run into 
  17.  > overflow problems, this will not work.  Anyhow,
  18.  > 
  19.  >     s = x+y;
  20.  >     d = abs(x-y);
  21.  >     max = (s+d)/2;
  22.  >     min = (s-d)/2;
  23.  > 
  24. Or, if your machine can do an arithmetic right shift over the complete word:
  25.     d = x-y
  26.     e = d >> BITSPERWORD
  27.     d &= e
  28.     max = x - d
  29.     min = y + d
  30. -- 
  31. dik t. winter, cwi, kruislaan 413, 1098 sj  amsterdam, nederland
  32. home: bovenover 215, 1025 jn  amsterdam, nederland; e-mail: dik@cwi.nl
  33.