X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fwarpzonelib%2Fmathlib.qc;h=92b7ee14dd9080d2fac9d17527042f929cbe3433;hb=70b84d37e2cf1d5336c327cb43593024de2a2c6c;hp=42262102e50b16421ae0a80003ba817bf8c34b58;hpb=406b13f464e47f8ca373b6bbe8ebe3bfc0f6be44;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/warpzonelib/mathlib.qc b/qcsrc/warpzonelib/mathlib.qc index 42262102e..92b7ee14d 100644 --- a/qcsrc/warpzonelib/mathlib.qc +++ b/qcsrc/warpzonelib/mathlib.qc @@ -1,3 +1,9 @@ +#include "mathlib.qh" +#if defined(CSQC) +#elif defined(MENUQC) +#elif defined(SVQC) +#endif + int fpclassify(float x) { if(isnan(x)) @@ -8,25 +14,25 @@ int fpclassify(float x) return FP_ZERO; return FP_NORMAL; } -int isfinite(float x) +bool isfinite(float x) { return !(isnan(x) || isinf(x)); } -int isinf(float x) +bool isinf(float x) { return (x != 0) && (x + x == x); } -int isnan(float x) +bool isnan(float x) { float y; y = x; return (x != y); } -int isnormal(float x) +bool isnormal(float x) { return isfinite(x); } -int signbit(float x) +bool signbit(float x) { return (x < 0); } @@ -72,9 +78,9 @@ float expm1(float x) vector frexp(float x) { vector v; - v_z = 0; - v_y = ilogb(x) + 1; - v_x = x / exp2(v_y); + v.z = 0; + v.y = ilogb(x) + 1; + v.x = x / exp2(v.y); return v; } int ilogb(float x) @@ -85,6 +91,10 @@ float ldexp(float x, int e) { return x * pow(2, e); } +float logn(float x, float base) +{ + return log(x) / log(base); +} float log10(float x) { return log(x) * M_LOG10E; @@ -146,11 +156,11 @@ vector lgamma(float x) // gamma(1-z) * gamma(z) = pi / sin(pi*z) // lgamma(1-z) + lgamma(z) = log(pi) - log(sin(pi*z)) // sign of gamma(1-z) = sign of gamma(z) * sign of sin(pi*z) - v_z = sin(M_PI * x); - v_x = log(M_PI) - log(fabs(v_z)) - v_x; - if(v_z < 0) - v_y = -v_y; - v_z = 0; + v.z = sin(M_PI * x); + v.x = log(M_PI) - log(fabs(v.z)) - v.x; + if(v.z < 0) + v.y = -v.y; + v.z = 0; return v; } if(x < 1.1) @@ -162,7 +172,21 @@ float tgamma(float x) { vector v; v = lgamma(x); - return exp(v_x) * v_y; + return exp(v.x) * v.y; +} + +/** + * Pythonic mod: + * TODO: %% operator? + * + * 1 % 2 == 1 + * -1 % 2 == 1 + * 1 % -2 == -1 + * -1 % -2 == -1 + */ +float pymod(float x, float y) +{ + return x - y * floor(x / y); } float nearbyint(float x) @@ -185,9 +209,9 @@ float remainder(float x, float y) vector remquo(float x, float y) { vector v; - v_z = 0; - v_y = rint(x / y); - v_x = x - y * v_y; + v.z = 0; + v.y = rint(x / y); + v.x = x - y * v.y; return v; } @@ -266,3 +290,11 @@ int isunordered(float x, float y) { return !(x < y || x == y || x > y); } + +vector cross(vector a, vector b) +{ + return + '1 0 0' * (a.y * b.z - a.z * b.y) + + '0 1 0' * (a.z * b.x - a.x * b.z) + + '0 0 1' * (a.x * b.y - a.y * b.x); +}