// and assert that the global vectors are NaN before calling the raw functions here
// to make sure nobody (even builtins) is accidentally using them - NaN is the most likely value to expose remaining usages
- // TODO make sure `isnan` actually works - potential compiler bug:
- //LOG_INFOF("%f\n", 0.0/0.0 == 0.0/0.0);
- //LOG_INFOF("%f\n", 0.0/0.0 != 0.0/0.0);
- //float x = 0.0/0.0;
- //LOG_INFOF("%f\n", x == x);
- //LOG_INFOF("%f\n", x != x);
-
- //float y = __builtin_nan();
- //LOG_INFOF("%f\n", y);
- //LOG_INFOF("%f\n", y == y);
- //LOG_INFOF("%f\n", __builtin_isnan(y));
-
CLEAR_V_GLOBALS();
}
#endif
const float FLOAT_MAX = 340282346638528859811704183484516925440.0f;
const float FLOAT_EPSILON = 0.00000011920928955078125f;
+/// Always use `isnan` function to compare because `float x = FLOAT_NAN; x == x;` gives true
const float FLOAT_NAN = 0.0 / 0.0;
}
bool isnan(float e)
{
- float f = e;
- return (e != f);
+ // the sane way to detect NaN is broken because of a compiler bug
+ // (works with constants but breaks when assigned to variables)
+ // use conversion to string instead
+
+ //float f = e;
+ //return (e != f);
+ return ftos(e) == "-nan";
}
bool isnormal(float e)
{
{
return fabs(e) * ((f>0) ? 1 : -1);
}
+/// Always use `isnan` function to compare because `float x = nan(); x == x;` gives true
float nan(string tag)
{
return sqrt(-1);