From: Graylunchbox74 Date: Tue, 12 Jan 2021 23:08:22 +0000 (-0600) Subject: added pow function X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=96d3cda29fe5909523f0e92288624d8f859e42dc;p=onyx.git added pow function --- diff --git a/core/math.onyx b/core/math.onyx index a0e19c5e..812c70f6 100644 --- a/core/math.onyx +++ b/core/math.onyx @@ -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 { + +}