]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/warpzonelib/mathlib.qc
Listbox / Picker: Implement item fading in a different way so that it gets influenced...
[xonotic/xonotic-data.pk3dir.git] / qcsrc / warpzonelib / mathlib.qc
index 42262102e50b16421ae0a80003ba817bf8c34b58..c9cde9072c34210fb2f387f137569dfa35f71d9e 100644 (file)
@@ -1,3 +1,13 @@
+#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)
 {
        if(isnan(x))
@@ -8,25 +18,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 +82,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)
@@ -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);
+}