]> git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/warpzone/mathlib.qc
Merge branch 'master' into Lyberta/WaypointIcons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / warpzone / mathlib.qc
index 4a7c8861069f7eb8420ec819b9525d606ffbe2d2..2b1d00c2cccca49056f80f877d8574a483000cdf 100644 (file)
@@ -24,8 +24,17 @@ bool isinf(float e)
 }
 bool isnan(float e)
 {
-       float f = e;
-       return (e != f);
+       // The sane way to detect NaN is this:
+       // float f = e;
+       // return (e != f);
+       // but darkplaces used to be compiled with -ffinite-math-only which broke it.
+       // DP is fixed now but until all clients update (so after 0.8.3) we have to use the following workaround
+       // or they'd have issues when connecting to newer servers.
+
+       // Negative NaN ("-nan") is much more common but plain "nan" can be created by negating *some* -nans so we need to check both.
+       // DP's QCVM and GMQCC's QCVM behave differently - one needs ftos(-(0.0 / 0.0)), the other ftos(-sqrt(-1)).
+       string s = ftos(e);
+       return s == "nan" || s == "-nan";
 }
 bool isnormal(float e)
 {
@@ -217,6 +226,7 @@ float copysign(float e, float f)
 {
        return fabs(e) * ((f>0) ? 1 : -1);
 }
+
 float nan(string tag)
 {
        return sqrt(-1);