Re: SIGN function: signof(num or array of num) [message #70142] |
Tue, 16 March 2010 07:01 |
Kenneth P. Bowman
Messages: 585 Registered: May 2000
|
Senior Member |
|
|
In article <809h2gFboaU1@mid.individual.net>,
Carsten Lechte <chl@toppoint.de> wrote:
> F�LDY Lajos wrote:
>> I think SIGNOF() should not cause an arithmetic error for finite numbers.
>
> I use the expression
>
> (x GT 0) -1* (x LT 0)
>
> to get the sign of e.g.
>
> x = [ -2e4, 5, 0, 1d/0, -1d/0, 0d/0 ]
>
> but it uses 2 comparisons and even a multiplication. Does anyone have
> a simpler/faster version? Furthermore, what should the sign of NaN be?
>
>
> chl
ITTVIS really needs to provide a fully vectorized, tested, SIGNUM
function that can handle all the various input types.
Ken Bowman
|
|
|
Re: SIGN function: signof(num or array of num) [message #70143 is a reply to message #70142] |
Tue, 16 March 2010 06:57  |
Carsten Lechte
Messages: 124 Registered: August 2006
|
Senior Member |
|
|
F�LDY Lajos wrote:
> I think SIGNOF() should not cause an arithmetic error for finite numbers.
I use the expression
(x GT 0) -1* (x LT 0)
to get the sign of e.g.
x = [ -2e4, 5, 0, 1d/0, -1d/0, 0d/0 ]
but it uses 2 comparisons and even a multiplication. Does anyone have
a simpler/faster version? Furthermore, what should the sign of NaN be?
chl
|
|
|
Re: SIGN function: signof(num or array of num) [message #70144 is a reply to message #70143] |
Tue, 16 March 2010 06:31  |
Foldy Lajos
Messages: 268 Registered: October 2001
|
Senior Member |
|
|
On Tue, 16 Mar 2010, Ding wrote:
> Dear IDL users,
>
> I cannot find the SIGN function in IDL procedures, but one in
> Solarsoft ssw/maths/ SIGN which occupy the name, but different
> purpose( sign(a)*b). so I wrote the SIGNOF() function which is to get
> the sign of a number or array,
>
> Hopefully I am not repeating someone' work! you are welcome to
> comments!
>
> return, fix(abs(input)/input)
IDL> input=0 & help, fix(abs(input)/input)
<Expression> INT = 0
% Program caused arithmetic error: Integer divide by 0
I think SIGNOF() should not cause an arithmetic error for finite numbers.
regards,
lajos
|
|
|