Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!newstop!texsun!convex!usenet From: dodson@convex.COM (Dave Dodson) Newsgroups: comp.lang.fortran Subject: Re: MAX function, but carry sign Message-ID: <1991Apr12.151639.18041@convex.com> Date: 12 Apr 91 15:16:39 GMT References: <282@venice.water.ca.gov> Sender: usenet@convex.com (news access account) Reply-To: dodson@convex.COM (Dave Dodson) Organization: Convex Computer Corporation, Richardson, Tx. Lines: 21 Nntp-Posting-Host: mozart.convex.com In article <282@venice.water.ca.gov> rfinch@caldwr.water.ca.gov (Ralph Finch) writes: > >I wish to use the max function on absolute values, but carry the sign >of the original values. That is: > >a=max(abs(a1),abs(a2)) ! but a has sign of either a1 or a2 > >I'm doing this with an IF statement now but wonder if there isn't some >combination of max and sign that will give the same result without an >IF statement. Try the following: a=sign(max(abs(a1),abs(a2)),(1+sign(1,abs(a1)-abs(a2)))*a1+(1-sign(1,abs(a1)-abs(a2)))*a2) It even makes the IF statement look good, doesn't it? ---------------------------------------------------------------------- Dave Dodson dodson@convex.COM Convex Computer Corporation Richardson, Texas (214) 497-4234