🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.lang.asm
Article #131

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

#131
From: Herman Rubin
Date: Thu, 31 Dec 1992 15:34
20 lines
1263 bytes
In article <1992Dec30.152808.25311@netcom.com> tm@netcom.com (Toshiyasu Morita) writes:
>I'm looking for a fast min() and max() algorithm, preferably without branching.

>Anyone know of any?

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;

-- 
Herman Rubin, Dept. of Statistics, Purdue Univ., West Lafayette IN47907-1399
Phone: (317)494-6054
hrubin@snap.stat.purdue.edu (Internet, bitnet)  
{purdue,pur-ee}!snap.stat!hrubin(UUCP)
Technical Details
Message-ID: <C04r9K.92o@mentor.cc.purdue.edu>
Path: arc1-ca.pugleaf.net!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
References: <1992Dec30.152808.25311@netcom.com>

Show Full Headers
Complete Article Headers
Newsgroups: alt.lang.asm
Path: arc1-ca.pugleaf.net!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
From: hrubin@pop.stat.purdue.edu (Herman Rubin)
Subject: Re: looking for fast min()/max()
Message-ID: <C04r9K.92o@mentor.cc.purdue.edu>
Keywords: speed min max
Sender: news@mentor.cc.purdue.edu (USENET News)
Organization: Purdue University Statistics Department
References: <1992Dec30.152808.25311@netcom.com>
Date: Thu, 31 Dec 1992 15:34:31 GMT
Lines: 20