[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Q]: ID analog to FORTRAN "sign" function
- Subject: Re: [Q]: ID analog to FORTRAN "sign" function
- From: "Mark Hadfield" <m.hadfield(at)niwa.cri.nz>
- Date: Tue, 10 Oct 2000 10:45:57 +1300
- Cache-Post-Path: clam-ext!unknown@gust.niwa.cri.nz
- Newsgroups: comp.lang.idl-pvwave
- Organization: NIWA
- References: <39DEB5DD.3B262CEB@maxwell.apphy.fukui-u.ac.jp> <39E1C067.16F7488E@pet.mpin-koeln.mpg.de>
- Xref: news.doit.wisc.edu comp.lang.idl-pvwave:21654
"Alex Schuster" <alex@pet.mpin-koeln.mpg.de> wrote in message
39E1C067.16F7488E@pet.mpin-koeln.mpg.de">news:39E1C067.16F7488E@pet.mpin-koeln.mpg.de...
> Rostyslav Pavlichenko wrote:
>
> > Does the IDl have something close to Fortran SIGN (DSIGN... so on...)
> > functions
> > ...
> > result = SIGN (a, b)
> > a (Input) Must be of type integer or real.
> >
> > b Must have the same type and kind parameters as a.
> >
> > 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
The following is more compact and works when b is an array
return, abs(a) * (fix(b ge 0) - fix(b lt 0))
---
Mark Hadfield
m.hadfield@niwa.cri.nz http://katipo.niwa.cri.nz/~hadfield/
National Institute for Water and Atmospheric Research
PO Box 14-901, Wellington, New Zealand
Hi! I'm a .signature virus! copy me into your .signature file to help me
spread!