Hi, how does one test for NaN? The following if statement is skipped, although 'rad' is NaN
Lang.NaN doesn't work either (doesn't compile). "try/catch" doesn't catch it either.
Thanks.
Hi, how does one test for NaN? The following if statement is skipped, although 'rad' is NaN
Lang.NaN doesn't work either (doesn't compile). "try/catch" doesn't catch it either.
Thanks.
That's bizarre but I think I found a workaround for you.
System.println(Math.acos(45d).toFloat().equals(Math.acos(45))); // true
class MathIsFun { static const negativeNan as Float = Math.acos…
I think this should work.
const FLT_MAX = 3.4028235e38f; function isnan(x as Float) as Boolean { return x != x; } function isinf(x as Float) as Boolean { return (x < -FLT_MAX || FLT_MAX…
LOL, now try this:
If I manually set it to NaN, it works with your code, but when it's returned through a Math function, nope! WTH!
Hard to find one when even this returns false :-(
That's bizarre but I think I found a workaround for you.
System.println(Math.acos(45d).toFloat().equals(Math.acos(45))); // true
class MathIsFun { static const negativeNan as Float = Math.acos(45); // (add ".toFloat()" to make type checker happy) public function isFinite(val as Number or Long or Float or Double) as Boolean { var valAsFloat = val.toFloat(); // this assumes that Infinity/-Infinity aren't possible in Monkey C. // if they are, we need to find a way to produce those values // (division by zero produces an error or exception) return !valAsFloat.equals(NaN) && !valAsFloat.equals(negativeNan); } }
Yep, that did the trick, thanks again :-)
I think this should work.
const FLT_MAX = 3.4028235e38f; function isnan(x as Float) as Boolean { return x != x; } function isinf(x as Float) as Boolean { return (x < -FLT_MAX || FLT_MAX < x); }