🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.lang.asm
Article #132

Re: looking for fast min()/max()

#132
From: Dik T. Winter
Date: Fri, 01 Jan 1993 01:51
20 lines
1131 bytes
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
Technical Details
Message-ID: <8493@charon.cwi.nl>
Path: arc1-ca.pugleaf.net!sparky!uunet!mcsun!sun4nl!cwi.nl!dik
References: <1992Dec30.152808.25311@netcom.com> <C04r9K.92o@mentor.cc.purdue.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!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