Odd behavior with NaNs [message #93513] |
Tue, 09 August 2016 09:28  |
whdaffer
Messages: 10 Registered: January 2000
|
Junior Member |
|
|
At least, I think it's odd.
IDL> print,sqrt(!values.f_nan>0.0)
0.00000
% Program caused arithmetic error: Floating illegal operand
IDL>
-- while --
IDL> print,sqrt(!values.f_nan)
NaN
I was trying to protect against taking the sqrt of a negative number. I guess I could just remove the >0.0 and live with
DL> print,sqrt(-1)
-NaN
% Program caused arithmetic error: Floating illegal operand
whenever there are negative numbers in my data.
What does the community think? Bug? Feature?
whd
|
|
|
Re: Odd behavior with NaNs [message #93515 is a reply to message #93513] |
Tue, 09 August 2016 16:42  |
Craig Markwardt
Messages: 1869 Registered: November 1996
|
Senior Member |
|
|
On Tuesday, August 9, 2016 at 12:28:40 PM UTC-4, whdaffer wrote:
> At least, I think it's odd.
>
>
> IDL> print,sqrt(!values.f_nan>0.0)
> 0.00000
> % Program caused arithmetic error: Floating illegal operand
> IDL>
>
> -- while --
>
> IDL> print,sqrt(!values.f_nan)
> NaN
>
> I was trying to protect against taking the sqrt of a negative number. I guess I could just remove the >0.0 and live with
>
> DL> print,sqrt(-1)
> -NaN
> % Program caused arithmetic error: Floating illegal operand
>
> whenever there are negative numbers in my data.
>
> What does the community think? Bug? Feature?
>
> whd
I'd usually use WHERE() to protect against that kind of input range issue. But you're right, it's strange that this happens. It's also documented to be platform-dependent!
http://www.harrisgeospatial.com/docs/Minimum_and_Maximum_Ope r.html
Craig
|
|
|