home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!mcsun!sun4nl!cwi.nl!dik
- From: dik@cwi.nl (Dik T. Winter)
- Newsgroups: alt.lang.asm
- Subject: Re: looking for fast min()/max()
- Keywords: speed min max
- Message-ID: <8493@charon.cwi.nl>
- Date: 1 Jan 93 01:51:55 GMT
- References: <1992Dec30.152808.25311@netcom.com> <C04r9K.92o@mentor.cc.purdue.edu>
- Sender: news@cwi.nl
- Organization: CWI, Amsterdam
- Lines: 20
-
- In article <C04r9K.92o@mentor.cc.purdue.edu> hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
- > I do not know how fast this is, and it requires having an absolute value.
- > The absolute value on 2's complement machines can be gotten around, but
- > again, unless the sum and difference of the numbers do not run into
- > overflow problems, this will not work. Anyhow,
- >
- > s = x+y;
- > d = abs(x-y);
- > max = (s+d)/2;
- > min = (s-d)/2;
- >
- Or, if your machine can do an arithmetic right shift over the complete word:
- d = x-y
- e = d >> BITSPERWORD
- d &= e
- max = x - d
- min = y + d
- --
- dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland
- home: bovenover 215, 1025 jn amsterdam, nederland; e-mail: dik@cwi.nl
-