Skip to content

Commit

Permalink
Test that nearest isn't JS' Math.round or C's round(3).
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Oct 2, 2015
1 parent 615c011 commit 8d3831a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ml-proto/TestingTodo.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ Floating point semantics:
- ~~test that all operations that can divide by zero produce Infinity with the correct sign~~
- ~~test that all operations that can have an invalid produce NaN~~
- test that all operations that can have underflow behave [correctly](https://github.com/WebAssembly/design/issues/148)
- test that nearestint doesn't do JS-style Math.round or C-style round(3) rounding
- ~~test that nearestint doesn't do JS-style Math.round or C-style round(3) rounding~~
- test that signalling NaN doesn't cause weirdness
- test that signalling/quiet NaNs can have sign bits and payloads in literals
- test that conversion from int32/int64 to float32 rounds correctly
Expand Down
13 changes: 13 additions & 0 deletions ml-proto/test/float_misc.wast
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
(func $f32.abs (param $x f32) (result f32) (f32.abs (get_local $x)))
(func $f32.neg (param $x f32) (result f32) (f32.neg (get_local $x)))
(func $f32.copysign (param $x f32) (param $y f32) (result f32) (f32.copysign (get_local $x) (get_local $y)))
(func $f32.nearest (param $x f32) (result f32) (f32.nearest (get_local $x)))

(func $f64.add (param $x f64) (param $y f64) (result f64) (f64.add (get_local $x) (get_local $y)))
(func $f64.sub (param $x f64) (param $y f64) (result f64) (f64.sub (get_local $x) (get_local $y)))
Expand All @@ -16,6 +17,7 @@
(func $f64.abs (param $x f64) (result f64) (f64.abs (get_local $x)))
(func $f64.neg (param $x f64) (result f64) (f64.neg (get_local $x)))
(func $f64.copysign (param $x f64) (param $y f64) (result f64) (f64.copysign (get_local $x) (get_local $y)))
(func $f64.nearest (param $x f64) (result f64) (f64.nearest (get_local $x)))

(export "f32.add" $f32.add)
(export "f32.sub" $f32.sub)
Expand All @@ -25,6 +27,7 @@
(export "f32.abs" $f32.abs)
(export "f32.neg" $f32.neg)
(export "f32.copysign" $f32.copysign)
(export "f32.nearest" $f32.nearest)

(export "f64.add" $f64.add)
(export "f64.sub" $f64.sub)
Expand All @@ -34,6 +37,7 @@
(export "f64.abs" $f64.abs)
(export "f64.neg" $f64.neg)
(export "f64.copysign" $f64.copysign)
(export "f64.nearest" $f64.nearest)
)

(assert_eq_bits (invoke "f32.add" (f32.const 1.1234567890) (f32.const 1.2345e-10)) (f32.const 1.123456789))
Expand Down Expand Up @@ -196,3 +200,12 @@
(assert_eq_bits (invoke "f64.copysign" (f64.const nan(0x0f1e27a6b)) (f64.const -nan)) (f64.const -nan(0x0f1e27a6b)))
(assert_eq_bits (invoke "f64.copysign" (f64.const -nan(0x0f1e27a6b)) (f64.const nan)) (f64.const nan(0x0f1e27a6b)))
(assert_eq_bits (invoke "f64.copysign" (f64.const -nan(0x0f1e27a6b)) (f64.const -nan)) (f64.const -nan(0x0f1e27a6b)))

;; Ties should not round halfway cases away from zero (as C's round(3) does)
;; or up (as JS's Math.round does).
(assert_eq_bits (invoke "f32.nearest" (f32.const 4.5)) (f32.const 4.0))
(assert_eq_bits (invoke "f32.nearest" (f32.const -4.5)) (f32.const -4.0))
(assert_eq_bits (invoke "f32.nearest" (f32.const -3.5)) (f32.const -4.0))
(assert_eq_bits (invoke "f64.nearest" (f64.const 4.5)) (f64.const 4.0))
(assert_eq_bits (invoke "f64.nearest" (f64.const -4.5)) (f64.const -4.0))
(assert_eq_bits (invoke "f64.nearest" (f64.const -3.5)) (f64.const -4.0))

0 comments on commit 8d3831a

Please sign in to comment.