[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Q]: ID analog to FORTRAN "sign" function




Alex Schuster <alex@pet.mpin-koeln.mpg.de> writes:
> > Results:
> > =========
> > The result type is the same as a.
> > The value of the result is
> > | a | if b >= zero
> > and -| a | if b < zero.
> 
> No, but you can easily write it:
> 
> function sign, a, b
>   if ( b ge 0 ) then $
>     return, abs( a ) $
>   else $
>     return, -abs( a )
> end

And, after the vector elf is done with it:

function sign, a, b
  s = 2*(b GE 0) - 1  ;; +1 or -1
  return, s*abs(a)
end

This function works with B as a scalar or a vector.  If it's a vector
then it must have the same dimensions as A.

Craig

P.S. Recovering from pneumonia, Ugh.
-- 
--------------------------------------------------------------------------
Craig B. Markwardt, Ph.D.         EMAIL:    craigmnet@cow.physics.wisc.edu
Astrophysics, IDL, Finance, Derivatives | Remove "net" for better response
--------------------------------------------------------------------------