aboutsummaryrefslogtreecommitdiff
path: root/core/math/math.odin
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2024-06-02 23:29:43 +0100
committergingerBill <bill@gingerbill.org>2024-06-02 23:29:43 +0100
commitb56a0e0f0346237a3254045ee68e539cfcb11be1 (patch)
treee59a20f74dd2347c5e1171e092337786813af0c9 /core/math/math.odin
parent0e2b7554c7f58ea34abfe47fa3b26b9c8c8388ce (diff)
Remove `libm` dependency in `core:math` where possiblecustom-math-sin
Diffstat (limited to 'core/math/math.odin')
-rw-r--r--core/math/math.odin32
1 files changed, 29 insertions, 3 deletions
diff --git a/core/math/math.odin b/core/math/math.odin
index 8d85c2381..534ef35f7 100644
--- a/core/math/math.odin
+++ b/core/math/math.odin
@@ -14,10 +14,10 @@ Float_Class :: enum {
Neg_Inf, // negative infinity
}
-TAU :: 6.28318530717958647692528676655900576
-PI :: 3.14159265358979323846264338327950288
+TAU :: 6.28318530717958647692528676655900576
+PI :: 3.14159265358979323846264338327950288
-E :: 2.71828182845904523536
+E :: 2.71828182845904523536
τ :: TAU
π :: PI
@@ -42,6 +42,32 @@ min :: builtin.min
max :: builtin.max
clamp :: builtin.clamp
+
+@(private)
+IS_WASM :: ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32
+
+@(require_results)
+sqrt_f16 :: proc "contextless" (x: f16) -> f16 {
+ when IS_WASM {
+ return f16(sqrt_f64(f64(x)))
+ } else {
+ return intrinsics.sqrt(x)
+ }
+}
+@(require_results)
+sqrt_f32 :: proc "contextless" (x: f32) -> f32 {
+ when IS_WASM {
+ return f32(sqrt_f64(f64(x)))
+ } else {
+ return intrinsics.sqrt(x)
+ }
+}
+@(require_results)
+sqrt_f64 :: proc "contextless" (x: f64) -> f64 {
+ return intrinsics.sqrt(x)
+}
+
+
@(require_results) sqrt_f16le :: proc "contextless" (x: f16le) -> f16le { return #force_inline f16le(sqrt_f16(f16(x))) }
@(require_results) sqrt_f16be :: proc "contextless" (x: f16be) -> f16be { return #force_inline f16be(sqrt_f16(f16(x))) }
@(require_results) sqrt_f32le :: proc "contextless" (x: f32le) -> f32le { return #force_inline f32le(sqrt_f32(f32(x))) }