We are about to switch to a new forum software. Until then we have removed the registration on this forum.
HI ,
I am struck with this small problem.Would some one help me to find way out ??
Am performing small calculation where I am not sure whether it will return the valid result or not .
For some iteration it returns the NaN (Not a Number). But what i want is to skip such iteration.
ie. if my result NaN for the iteration 5 then I would like to skip that iteration and move to the next .
here is sample.
float result;
for(int i =0; to say some 100)
{
result = some operation;
if (result==NaN)
{
result= 0;
}
sum = sum + result;
}
Answers
Float.isNaN(result)
Fastest way is
if (result != result) continue;
. ~O)It's also more cross-mode compatible w/ "JS Mode" than Float.isNaN(). L-)
@benja : thank u @GoToLoop : Thank U
An alt. version which relies on the ternary conditional operator
?:
: :Dhttps://Processing.org/reference/conditional.html
P.S.: Uncomment line
for (float f : VALS) r += f;
in order to see theNaN
result. >-)