]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
document isnan
authorMartin Taibr <taibr.martin@gmail.com>
Fri, 16 Nov 2018 09:57:30 +0000 (10:57 +0100)
committerMartin Taibr <taibr.martin@gmail.com>
Fri, 16 Nov 2018 09:57:30 +0000 (10:57 +0100)
qcsrc/lib/deglobalization.qh
qcsrc/lib/float.qh
qcsrc/lib/warpzone/mathlib.qc

index 315ff6d6a36a963ab4e6b75418ecab346d1546f8..21f303a3e0bea19fd89393603f81f4ccd306ea9c 100644 (file)
@@ -31,18 +31,6 @@ STATIC_INIT(globals) {
        // 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
index fa4ff77b5a1fee7cfb7d6c4f8312999aec33e53c..b35494de44c0334f776d296f808565dd33af8be8 100644 (file)
@@ -2,4 +2,5 @@
 
 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;
index 4a7c8861069f7eb8420ec819b9525d606ffbe2d2..9105269ff32ebbc00d9c54e832557943412cedd4 100644 (file)
@@ -24,8 +24,13 @@ bool isinf(float e)
 }
 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)
 {
@@ -217,6 +222,7 @@ float copysign(float e, float f)
 {
        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);