X-Git-Url: https://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fwarpzonelib%2Fmathlib.qc;h=f61712d2322dc8436b7bd0675ee1a32103f87ba1;hb=2d29a97f94a5b28bee1a909ba5e47abf352ac751;hp=b948b203eeb36ac4a06d00b6a91ab038b6dc1be3;hpb=99facb38338832f539cec7022c414f7a6de458c3;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/warpzonelib/mathlib.qc b/qcsrc/warpzonelib/mathlib.qc index b948b203e..f61712d23 100644 --- a/qcsrc/warpzonelib/mathlib.qc +++ b/qcsrc/warpzonelib/mathlib.qc @@ -1,11 +1,10 @@ +#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" + #include "../dpdefs/progsdefs.qh" #endif int fpclassify(float x) @@ -95,6 +94,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; @@ -175,6 +178,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); @@ -276,3 +293,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); +}