aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorJeroen van Rijn <Kelimion@users.noreply.github.com>2023-11-04 22:14:44 +0100
committerJeroen van Rijn <Kelimion@users.noreply.github.com>2023-11-04 22:14:44 +0100
commit620128046801eb6b5156e58e386d2b42a4e7ae68 (patch)
treec95a049f2d6537b22a2cefcbaa8d530bf95a2118 /tests
parent5edb2c568840248f63de3fab58a02f134f182525 (diff)
Add math.pow2_f{16,32,64}, fast floating point 2^x where x is an integer.
Diffstat (limited to 'tests')
-rw-r--r--tests/internal/Makefile7
-rw-r--r--tests/internal/build.bat3
-rw-r--r--tests/internal/test_pow.odin67
3 files changed, 74 insertions, 3 deletions
diff --git a/tests/internal/Makefile b/tests/internal/Makefile
index 898ba0517..00e46197b 100644
--- a/tests/internal/Makefile
+++ b/tests/internal/Makefile
@@ -1,9 +1,12 @@
ODIN=../../odin
-all: rtti_test map_test
+all: rtti_test map_test pow_test
rtti_test:
$(ODIN) run test_rtti.odin -file -vet -strict-style -o:minimal
map_test:
- $(ODIN) run test_map.odin -file -vet -strict-style -o:minimal \ No newline at end of file
+ $(ODIN) run test_map.odin -file -vet -strict-style -o:minimal
+
+pow_test:
+ $(ODIN) run test_pow.odin -file -vet -strict-style -o:minimal \ No newline at end of file
diff --git a/tests/internal/build.bat b/tests/internal/build.bat
index 1f40885bb..f289d17fa 100644
--- a/tests/internal/build.bat
+++ b/tests/internal/build.bat
@@ -2,4 +2,5 @@
set PATH_TO_ODIN==..\..\odin
rem %PATH_TO_ODIN% run test_rtti.odin -file -vet -strict-style -o:minimal || exit /b
%PATH_TO_ODIN% run test_map.odin -file -vet -strict-style -o:minimal || exit /b
-rem -define:SEED=42 \ No newline at end of file
+rem -define:SEED=42
+%PATH_TO_ODIN% run test_pow.odin -file -vet -strict-style -o:minimal || exit /b \ No newline at end of file
diff --git a/tests/internal/test_pow.odin b/tests/internal/test_pow.odin
new file mode 100644
index 000000000..b169e1361
--- /dev/null
+++ b/tests/internal/test_pow.odin
@@ -0,0 +1,67 @@
+package test_internal_math_pow
+
+import "core:fmt"
+import "core:math"
+import "core:os"
+import "core:testing"
+
+@test
+pow_test :: proc(t: ^testing.T) {
+ for exp in -2000..=2000 {
+ {
+ v1 := math.pow(2, f64(exp))
+ v2 := math.pow2_f64(exp)
+ _v1 := transmute(u64)v1
+ _v2 := transmute(u64)v2
+ expect(t, _v1 == _v2, fmt.tprintf("Expected math.pow2_f64(%d) == math.pow(2, %d) (= %x), got %x", exp, exp, v1, v2))
+ }
+ {
+ v1 := math.pow(2, f32(exp))
+ v2 := math.pow2_f32(exp)
+ _v1 := transmute(u32)v1
+ _v2 := transmute(u32)v2
+ expect(t, _v1 == _v2, fmt.tprintf("Expected math.pow2_f32(%d) == math.pow(2, %d) (= %x), got %x", exp, exp, v1, v2))
+ }
+ {
+ v1 := math.pow(2, f16(exp))
+ v2 := math.pow2_f16(exp)
+ _v1 := transmute(u16)v1
+ _v2 := transmute(u16)v2
+ expect(t, _v1 == _v2, fmt.tprintf("Expected math.pow2_f16(%d) == math.pow(2, %d) (= %x), got %x", exp, exp, v1, v2))
+ }
+ }
+}
+
+// -------- -------- -------- -------- -------- -------- -------- -------- -------- --------
+
+main :: proc() {
+ t := testing.T{}
+
+ pow_test(&t)
+
+ fmt.printf("%v/%v tests successful.\n", TEST_count - TEST_fail, TEST_count)
+ if TEST_fail > 0 {
+ os.exit(1)
+ }
+}
+
+TEST_count := 0
+TEST_fail := 0
+
+when ODIN_TEST {
+ expect :: testing.expect
+ log :: testing.log
+} else {
+ expect :: proc(t: ^testing.T, condition: bool, message: string, loc := #caller_location) {
+ TEST_count += 1
+ if !condition {
+ TEST_fail += 1
+ fmt.printf("[%v] %v\n", loc, message)
+ return
+ }
+ }
+ log :: proc(t: ^testing.T, v: any, loc := #caller_location) {
+ fmt.printf("[%v] ", loc)
+ fmt.printf("log: %v\n", v)
+ }
+} \ No newline at end of file