X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fwarpzonelib%2Fmathlib.qc;h=92b7ee14dd9080d2fac9d17527042f929cbe3433;hb=70b84d37e2cf1d5336c327cb43593024de2a2c6c;hp=b45c22a21ff210e785ac88827bafc337bb6320c1;hpb=35e8f712933b0ebf9b163b7289cf975825b33803;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/warpzonelib/mathlib.qc b/qcsrc/warpzonelib/mathlib.qc index b45c22a21..92b7ee14d 100644 --- a/qcsrc/warpzonelib/mathlib.qc +++ b/qcsrc/warpzonelib/mathlib.qc @@ -1,11 +1,7 @@ +#include "mathlib.qh" #if defined(CSQC) - #include "../dpdefs/csprogsdefs.qh" - #include "mathlib.qh" #elif defined(MENUQC) #elif defined(SVQC) - #include "../dpdefs/progsdefs.qh" - #include "../dpdefs/dpextensions.qh" - #include "mathlib.qh" #endif int fpclassify(float x) @@ -18,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); } @@ -82,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) @@ -95,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; @@ -156,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; + 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.y = -v.y; + v.z = 0; return v; } if(x < 1.1) @@ -175,6 +175,20 @@ float tgamma(float x) 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) { return rint(x); @@ -195,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; } @@ -276,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); +}