aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaytan Laats <laytanlaats@hotmail.com>2025-02-06 21:20:15 +0100
committerLaytan Laats <laytanlaats@hotmail.com>2025-02-06 21:20:15 +0100
commit9241d7c69803ae388f06f0b593c018c63432f5eb (patch)
tree6f82ca72f047fcde634395852ec7f7e9d26dc229
parentde83ad2a251ec126a02378b83e4cae5b853e34ac (diff)
add tests for abs() on floats
-rw-r--r--tests/internal/test_abs.odin56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/internal/test_abs.odin b/tests/internal/test_abs.odin
new file mode 100644
index 000000000..2f7b67862
--- /dev/null
+++ b/tests/internal/test_abs.odin
@@ -0,0 +1,56 @@
+package test_internal
+
+import "core:testing"
+
+@(test)
+test_abs_float :: proc(t: ^testing.T) {
+ not_const :: proc(v: $T) -> T { return v }
+
+ // Constant f16
+ testing.expect_value(t, abs(f16(0.)), 0.)
+ testing.expect_value(t, abs(f16(-0.)), 0.)
+ testing.expect_value(t, abs(f16(-1.)), 1.)
+ testing.expect_value(t, abs(min(f16)), max(f16))
+ testing.expect_value(t, abs(max(f16)), max(f16))
+ testing.expect_value(t, abs(f16(-.12345)), .12345)
+
+ // Variable f16
+ testing.expect_value(t, abs(not_const(f16(0.))), 0.)
+ testing.expect_value(t, abs(not_const(f16(-0.))), 0.)
+ testing.expect_value(t, abs(not_const(f16(-1.))), 1.)
+ testing.expect_value(t, abs(not_const(min(f16))), max(f16))
+ testing.expect_value(t, abs(not_const(max(f16))), max(f16))
+ testing.expect_value(t, abs(not_const(f16(-.12345))), .12345)
+
+ // Constant f32
+ testing.expect_value(t, abs(f32(0.)), 0.)
+ testing.expect_value(t, abs(f32(-0.)), 0.)
+ testing.expect_value(t, abs(f32(-1.)), 1.)
+ testing.expect_value(t, abs(min(f32)), max(f32))
+ testing.expect_value(t, abs(max(f32)), max(f32))
+ testing.expect_value(t, abs(f32(-.12345)), .12345)
+
+ // Variable f32
+ testing.expect_value(t, abs(not_const(f32(0.))), 0.)
+ testing.expect_value(t, abs(not_const(f32(-0.))), 0.)
+ testing.expect_value(t, abs(not_const(f32(-1.))), 1.)
+ testing.expect_value(t, abs(not_const(min(f32))), max(f32))
+ testing.expect_value(t, abs(not_const(max(f32))), max(f32))
+ testing.expect_value(t, abs(not_const(f32(-.12345))), .12345)
+
+ // Constant f64
+ testing.expect_value(t, abs(f64(0.)), 0.)
+ testing.expect_value(t, abs(f64(-0.)), 0.)
+ testing.expect_value(t, abs(f64(-1.)), 1.)
+ testing.expect_value(t, abs(min(f64)), max(f64))
+ testing.expect_value(t, abs(max(f64)), max(f64))
+ testing.expect_value(t, abs(f64(-.12345)), .12345)
+
+ // Variable f64
+ testing.expect_value(t, abs(not_const(f64(0.))), 0.)
+ testing.expect_value(t, abs(not_const(f64(-0.))), 0.)
+ testing.expect_value(t, abs(not_const(f64(-1.))), 1.)
+ testing.expect_value(t, abs(not_const(min(f64))), max(f64))
+ testing.expect_value(t, abs(not_const(max(f64))), max(f64))
+ testing.expect_value(t, abs(not_const(f64(-.12345))), .12345)
+}