home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / alt / lang / asm / 522 < prev    next >
Encoding:
Text File  |  1992-12-31  |  1.2 KB  |  33 lines

  1. Newsgroups: alt.lang.asm
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!sdd.hp.com!news.cs.indiana.edu!noose.ecn.purdue.edu!mentor.cc.purdue.edu!pop.stat.purdue.edu!hrubin
  3. From: hrubin@pop.stat.purdue.edu (Herman Rubin)
  4. Subject: Re: looking for fast min()/max()
  5. Message-ID: <C04r9K.92o@mentor.cc.purdue.edu>
  6. Keywords: speed min max
  7. Sender: news@mentor.cc.purdue.edu (USENET News)
  8. Organization: Purdue University Statistics Department
  9. References: <1992Dec30.152808.25311@netcom.com>
  10. Date: Thu, 31 Dec 1992 15:34:31 GMT
  11. Lines: 20
  12.  
  13. In article <1992Dec30.152808.25311@netcom.com> tm@netcom.com (Toshiyasu Morita) writes:
  14. >I'm looking for a fast min() and max() algorithm, preferably without branching.
  15.  
  16. >Anyone know of any?
  17.  
  18. I do not know how fast this is, and it requires having an absolute value.
  19. The absolute value on 2's complement machines can be gotten around, but
  20. again, unless the sum and difference of the numbers do not run into 
  21. overflow problems, this will not work.  Anyhow,
  22.  
  23.     s = x+y;
  24.     d = abs(x-y);
  25.     max = (s+d)/2;
  26.     min = (s-d)/2;
  27.  
  28. -- 
  29. Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
  30. Phone: (317)494-6054
  31. hrubin@snap.stat.purdue.edu (Internet, bitnet)  
  32. {purdue,pur-ee}!snap.stat!hrubin(UUCP)
  33.