]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/warpzonelib/mathlib.qc
Merge branch 'master' into Mario/vaporizer_damage
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / mathlib.qc
index b948b203eeb36ac4a06d00b6a91ab038b6dc1be3..f61712d2322dc8436b7bd0675ee1a32103f87ba1 100644 (file)
@@ -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);
+}