FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Syntax
(Moderators: fry, REAS)
   testing for inf. and NaN
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: testing for inf. and NaN  (Read 1085 times)
battey

WWW
testing for inf. and NaN
« on: Oct 4th, 2003, 7:48am »

I'm doing some chaos code where I need to test for values going into the stratosphere so I know I need to abandon the randomly generated initial conditions.
 
By hunting through Java documentation, I found a method for testing for infinity that works in P5:
 
newx==Float.POSITIVE_INFINITY
 
but I haven't been able to figure out how to test for NaN.
 
newx==Float.NaN  doesn't seem to do it. Doesn't generate an error, but also doesn't trap:
 
float x=Float.NaN;
 
if(x==Float.NaN)
{
  println("Not a number");
}
 

 
 
fry


WWW
Re: testing for inf. and NaN
« Reply #1 on: Oct 4th, 2003, 3:56pm »

the nan test is also the same as java:
 
if (Float.isNaN(someNumber)) {
  println("not a numbah");
}
 
since it's literally 'not a number', it doesn't equal anything, so == doesn't work.
 
Pages: 1 

« Previous topic | Next topic »