Page 1 of 1

How to tell if a variable is Infinity or NaN (not a number)?

PostPosted: Fri Jun 25, 2010 10:59 am
by JohnSchock
I'm playing with the BlindWatchMaker1.cobra program that came with the installation and making some changes to the code. I need to add an if statement which checks whether a variable is either NaN or Infinity, how would I do that?

Re: How to tell if a variable is Infinity or NaN (not a numb

PostPosted: Fri Jun 25, 2010 9:41 pm
by Charles
x.isNaN and x.isInfinity

In other words, these are properties on "float" typed values. You can see all the properties and methods on primitive types at the PrimitiveTypeMembers wiki page.

Re: How to tell if a variable is Infinity or NaN (not a numb

PostPosted: Fri Jun 25, 2010 9:43 pm
by Charles
more directly:
if x.isNaN or x.isInfinity, trace x

Re: How to tell if a variable is Infinity or NaN (not a numb

PostPosted: Fri Jun 25, 2010 9:49 pm
by Charles
One more note. You're always free to post questions here, but I just wanted to point out that if you use the wiki search for things like "infinity" you will get your answers even faster. And then, of course, it becomes interesting to find out what answers you did not get from the wiki so we (and possibly you) can expand it.

Our forums have a search as well. Unfortunately, these are two separate software packages and although we managed to integrate their user accounts, the searches are separate for now.

Re: How to tell if a variable is Infinity or NaN (not a numb

PostPosted: Fri Jun 25, 2010 10:11 pm
by JohnSchock
Chuck wrote:One more note. You're always free to post questions here, but I just wanted to point out that if you use the wiki search for things like "infinity" you will get your answers even faster.


Yea, I actually found the answer almost immediately after I posted :oops: