added pow function
authorGraylunchbox74 <collin.rumpca@trojans.dsu.edu>
Tue, 12 Jan 2021 23:08:22 +0000 (17:08 -0600)
committerGraylunchbox74 <collin.rumpca@trojans.dsu.edu>
Tue, 12 Jan 2021 23:08:22 +0000 (17:08 -0600)
core/math.onyx

index a0e19c5e964a080dcbeb07e8cced3cb79c055b22..812c70f6f523bc915aff993c885797836d57ecc4 100644 (file)
@@ -9,7 +9,8 @@ PI  :: 3.14159265f;
 TAU :: 6.28318330f;
 
 // Simple taylor series approximation of sin(t)
-sin :: proc (t: f32) -> f32 {
+sin :: proc (t_: f32) -> f32 {
+    t := t_;
     while t >=  PI do t -= TAU;
     while t <= -PI do t += TAU;
 
@@ -31,7 +32,8 @@ sin :: proc (t: f32) -> f32 {
 }
 
 // Simple taylor series approximation of cos(t)
-cos :: proc (t: f32) -> f32 {
+cos :: proc (t_: f32) -> f32 {
+    t := t_;
     while t >=  PI do t -= TAU;
     while t <= -PI do t += TAU;
 
@@ -74,3 +76,33 @@ abs_i64 :: proc (x: i64) -> i64 {
     return -x;
 }
 abs :: proc { abs_i32, abs_i64, abs_f32, abs_f64 }
+
+pow_int :: proc (base: $T, p: i32) -> T {
+    if base == 0 && p == 0 do return 1;
+    elseif p == 0 do return 1;
+    a := 1;
+    b := p;
+    c := base;
+    while b > 0 {
+        if b % 2 == 1 do a *= c;
+        b = b >> 1;
+        c *= c;
+    }
+    return a;
+}
+
+pow_float :: proc (base: $T, p: f32) -> T {
+    if base == 0 && p == 0 do return 1;
+    elseif p == 0 do return 1;
+
+}
+
+pow :: proc { pow_int, pow_float }
+
+ln :: proc (a: f32) -> f32 {
+
+}
+
+log :: proc (a: $T, b: $R) ->T {
+
+}