X-Git-Url: http://de.git.xonotic.org/?p=xonotic%2Fxonotic-data.pk3dir.git;a=blobdiff_plain;f=qcsrc%2Flib%2Fwarpzone%2Fmathlib.qc;h=9105269ff32ebbc00d9c54e832557943412cedd4;hp=acbc1c61d4dda0f69cb0d256467f16bc2808cb07;hb=991de5e6922cd3c283de56c3249624f0f1bfe767;hpb=30648cd6167b20ad5924c03cd39efff9ef5b62df diff --git a/qcsrc/lib/warpzone/mathlib.qc b/qcsrc/lib/warpzone/mathlib.qc index acbc1c61d4..9105269ff3 100644 --- a/qcsrc/lib/warpzone/mathlib.qc +++ b/qcsrc/lib/warpzone/mathlib.qc @@ -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);