Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!elroy.jpl.nasa.gov!ncar!csn!pikes!aspen.craycos.com!jrbd From: jrbd@craycos.com (James Davies) Newsgroups: comp.lang.fortran Subject: Re: MAX function, but carry sign Message-ID: <1991Apr12.151728.12916@craycos.com> Date: 12 Apr 91 15:17:28 GMT References: <282@venice.water.ca.gov> Organization: Cray Computer Corporation Lines: 19 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. If you want the result to carry the sign of the maximum value (which is the most likely case), then you could use the sign of the sum of the two, i.e. a = sign(max(abs(a1),abs(a2)), a1+a2) This will give you the positive value if they are the same, but the sign of the larger absolute value if they are different.