comp.lang.idl-pvwave archive
Messages from Usenet group comp.lang.idl-pvwave, compiled by Paulo Penteado

Home » Public Forums » archive » Odd behavior with NaNs
Show: Today's Messages :: Show Polls :: Message Navigator
E-mail to friend 
Switch to threaded view of this topic Create a new topic Submit Reply
Odd behavior with NaNs [message #93513] Tue, 09 August 2016 09:28 Go to next message
whdaffer is currently offline  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 Go to previous message
Craig Markwardt is currently offline  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
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Baffled by out of range subscript error
Next Topic: Running fortran exectuable using IDL spawn fails

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ] [ PDF ]

Current Time: Wed Oct 08 09:19:02 PDT 2025

Total time taken to generate the page: 0.00371 seconds