|
Author |
Topic: testing for inf. and NaN (Read 1085 times) |
|
battey
|
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
|
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.
|
|
|
|
|