test_pow.odin 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package test_internal_math_pow
  2. @(require) import "core:log"
  3. import "core:math"
  4. import "core:testing"
  5. @test
  6. pow_test :: proc(t: ^testing.T) {
  7. for exp in -2000..=2000 {
  8. {
  9. v1 := math.pow(2, f64(exp))
  10. v2 := math.pow2_f64(exp)
  11. _v1 := transmute(u64)v1
  12. _v2 := transmute(u64)v2
  13. if exp == -1075 && ODIN_OS == .Windows {
  14. // LLVM on Windows returns 0h00000000_00000001 for pow(2, -1075),
  15. // unlike macOS and Linux where it returns 0h00000000_00000000
  16. // pow2_f64 returns the same float on all platforms because it isn't this stupid
  17. _v1 = 0h00000000_00000000
  18. }
  19. testing.expectf(t, _v1 == _v2, "Expected math.pow2_f64(%d) == math.pow(2, %d) (= %16x), got %16x", exp, exp, _v1, _v2)
  20. }
  21. {
  22. v1 := math.pow(2, f32(exp))
  23. v2 := math.pow2_f32(exp)
  24. _v1 := transmute(u32)v1
  25. _v2 := transmute(u32)v2
  26. testing.expectf(t, _v1 == _v2, "Expected math.pow2_f32(%d) == math.pow(2, %d) (= %08x), got %08x", exp, exp, _v1, _v2)
  27. }
  28. {
  29. v1 := math.pow(2, f16(exp))
  30. v2 := math.pow2_f16(exp)
  31. _v2 := transmute(u16)v2
  32. _v1 := transmute(u16)v1
  33. when ODIN_OS == .Darwin && ODIN_ARCH == .arm64 {
  34. if exp == -25 {
  35. log.info("skipping known test failure on darwin+arm64, Expected math.pow2_f16(-25) == math.pow(2, -25) (= 0000), got 0001")
  36. _v2 = 0
  37. }
  38. }
  39. testing.expectf(t, _v1 == _v2, "Expected math.pow2_f16(%d) == math.pow(2, %d) (= %04x), got %04x", exp, exp, _v1, _v2)
  40. }
  41. }
  42. }