In many scripting programming languages, when a variable or atrribute of object has not been declared, it is "undefined". So an arithmetic operation is NaN (Not a Number) when a variable is undefined, null or incompatible type with number operation.
So I think in some "moment" mz, sz or TerrainDemo.FPS cause a invalid operation.
The solution is find which variable is NaN and set a default value for this situation (maybe using conditionals or return 0 when your operation is NaN).
P.S.: Some language, like Javascript, have the special values NaN and Infinity. So
- Infinity + -> Infinity
- Infinity - Infinity -> NaN
- Number / 0 -> Infinity (anothers raise an exception)
- Number / Infinity -> 0
To see all indeterminate forms go here.
TerrainDemo.FPS > 60 && mz == sz. IfTerrainDemo.FPSis a floating-point variable, then you might also need to make sure it is larger than 0. – barak manos Feb 25 '15 at 12:01TerrainDemo.FPS>60be a problem? IfTerrainDemo.FPS = 120andmz = sz, then(mz - sz) / (10 * (60 / TerrainDemo.FPS)= (mz - sz) / (10 * (60 / 120)=(mz - sz) / (10 * (0.5)) = 0, notNaN. – 5xum Feb 25 '15 at 12:03TerrainDemo.FPSwill sometimes be $0$. (OrmzorszalreadyNaN.) – mrf Feb 25 '15 at 12:05TerrainDemo.FPSis an integer type, then60/TerrainDemo.FPSwill be $0$, then10*0will also be $0$. Then, if one ofmzorszis a floating-point type, andmz == sz, you will get a floating-point division of $0$ by $0$, which will result withNaN. – barak manos Feb 25 '15 at 12:06TerrainDemo.FPSis an integer type, then(FPS > 60 || FPS < -60) && mz == szwill yieldNaN.IfTerrainDemo.FPSis a floating-point type, then(FPS == inf || FPS == -inf) && mz == szwill yieldNaN. – barak manos Feb 25 '15 at 12:15float,intandNaNare purely programming terms (and most definitely not mathematical ones). So everything here is in fact pretty much programming-related, and I guess that this is why the question was closed as "off-topic". There is simply no such thing asNaNin mathematics. As you can imagine, being the one whose answer has been accepted (by you), I would be more than happy to keep it here. But a month after being closed, it will be removed completely. That is why I have suggested to migrate it to what appears a more appropriate place for it. – barak manos Feb 25 '15 at 17:37NaNis just some bit-sequence defined by the most widely-used floating-point standard (IEEE-754) for that purpose. See here. – barak manos Feb 25 '15 at 23:44