summaryrefslogtreecommitdiff
path: root/stage3/math.h
diff options
context:
space:
mode:
authorLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-21 06:40:40 +0100
committerLizzy Fleckenstein <lizzy@vlhl.dev>2023-12-21 06:40:40 +0100
commit1ad6bbe4b3baee113bf6f37e0d02030910543fbd (patch)
tree52c419e11d50d1940911dba73b8c39eb8617724f /stage3/math.h
parent5885cb0a19b06388222f2945d78963377e584ecc (diff)
downloadcuddles-1ad6bbe4b3baee113bf6f37e0d02030910543fbd.tar.xz
add maths library and print_dbl
Diffstat (limited to 'stage3/math.h')
-rw-r--r--stage3/math.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/stage3/math.h b/stage3/math.h
new file mode 100644
index 0000000..6f7ae58
--- /dev/null
+++ b/stage3/math.h
@@ -0,0 +1,62 @@
+#ifndef MATH_H
+#define MATH_H
+
+// for now, stuff will be added in this file as it is needed
+
+#define PI 3.14159265358979323846
+
+/*double get_pi()
+{
+ double pi;
+ asm("fldpi; fstpl %0":"=m"(pi));
+ return pi;
+}*/
+
+static inline double sin(double x)
+{
+ asm("fldl %1; fsin; fstpl %0":"=m"(x):"m"(x));
+ return x;
+}
+
+static inline double rad(double x)
+{
+ return PI / 180.0 * x;
+}
+
+static inline double deg(double x)
+{
+ return 180.0 / PI * x;
+}
+
+static inline double fabs(double x)
+{
+ asm("fldl %1; fabs; fstpl %0":"=m"(x):"m"(x));
+ return x;
+}
+
+static inline double atan2(double x, double y)
+{
+ asm("fldl %1; fldl %2; fpatan; fstpl %0":"=m"(x):"m"(x),"m"(y));
+ return x;
+}
+
+static inline double sqrt(double x)
+{
+ asm("fldl %0; fsqrt; fstpl %0":"=m"(x):"m"(x));
+ return x;
+}
+
+static inline double acos(double x)
+{
+ return atan2(sqrt(1-x*x),x);
+}
+
+static inline long ipow(long b, unsigned long exp)
+{
+ long x = 1;
+ for (unsigned long i = 0; i < exp; i++)
+ x *= b;
+ return x;
+}
+
+#endif