]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/lib/warpzone/mathlib.qc
Merge branch 'master' into martin-t/globals
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / warpzone / mathlib.qc
index acbc1c61d4dda0f69cb0d256467f16bc2808cb07..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)
 {
@@ -63,11 +68,11 @@ float tanh(float e)
 
 float exp(float e)
 {
-       return (M_E ** e);
+       return pow(M_E, e);
 }
 float exp2(float e)
 {
-       return (2 ** e);
+       return pow(2, e);
 }
 float expm1(float e)
 {
@@ -79,16 +84,16 @@ vector frexp(float e)
        vector v;
        v.z = 0;
        v.y = ilogb(e) + 1;
-       v.x = e / (2 ** v.y);
+       v.x = e / pow(2, v.y);
        return v;
 }
 int ilogb(float e)
 {
        return floor(log2(fabs(e)));
 }
-float ldexp(float e, int e)
+float ldexp(float x, int e)
 {
-       return e * (2 ** e);
+       return x * pow(2, e);
 }
 float logn(float e, float base)
 {
@@ -117,12 +122,12 @@ vector modf(float f)
 
 float scalbn(float e, int n)
 {
-       return e * (2 ** n);
+       return e * pow(2, n);
 }
 
 float cbrt(float e)
 {
-       return copysign((fabs(e) ** (1.0/3.0)), e);
+       return copysign(pow(fabs(e), (1.0/3.0)), e);
 }
 float hypot(float e, float f)
 {
@@ -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);