Skip to content

Commit

Permalink
Merge pull request #77 from WebAssembly/nearest-fix
Browse files Browse the repository at this point in the history
Avoid relying on correct rounding of mod_float.
  • Loading branch information
sunfishcode committed Sep 18, 2015
2 parents 502fdf9 + be2d3a5 commit accca7a
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion ml-proto/src/given/float32.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ let nearest x =
let d = Pervasives.floor xf in
let um = abs_float (xf -. u) in
let dm = abs_float (xf -. d) in
let u_or_d = um < dm || ((um = dm) && (mod_float u 2.0 = 0.0)) in
let u_or_d = um < dm ||
(um = dm && let h = u /. 2. in Pervasives.floor h = h) in
let f = if u_or_d then u else d in
bits_of_arith f

Expand Down
3 changes: 2 additions & 1 deletion ml-proto/src/given/float64.ml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ let nearest x =
let d = Pervasives.floor xf in
let um = abs_float (xf -. u) in
let dm = abs_float (xf -. d) in
let u_or_d = um < dm || ((um = dm) && (mod_float u 2.0 = 0.0)) in
let u_or_d = um < dm ||
(um = dm && let h = u /. 2. in Pervasives.floor h = h) in
let f = if u_or_d then u else d in
bits_of_arith f

Expand Down

0 comments on commit accca7a

Please sign in to comment.