Skip to content

Avoid polymorphic comparison over float values #1048

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Jul 30, 2020
Merged

Avoid polymorphic comparison over float values #1048

merged 10 commits into from
Jul 30, 2020

Conversation

xclerc
Copy link
Collaborator

@xclerc xclerc commented Jul 30, 2020

While randomly walking through the code, I noticed something similar
to an old flambda bug. Indeed, with master, the following code (copied
from this pull request) prints inf instead of -inf:

let z =
  let x = -0. and y = +0. in
  if mod_float x 1. >= 0. then
    x
  else if false then x else y

let () =
  Printf.printf "%g\n" (1. /. z)

The culprit is the use of the polymorphic equality on float values by a join
operation in the Flow module. This pull request ensure that the equality
function over Code.constant value does not use the polymorphic equality.

@hhugo
Copy link
Member

hhugo commented Jul 30, 2020

Can you add a changelog entry ?

@xclerc
Copy link
Collaborator Author

xclerc commented Jul 30, 2020

I have added a changelog entry and pushed additional commits
to support OCaml 4.0{2,3,4}.

@hhugo
Copy link
Member

hhugo commented Jul 30, 2020

I've reformated the code with make fmt (depends on ocamlformat)
and moved foat_equal, int64_equal, array_equal in stdlib.ml

@hhugo hhugo merged commit 4b6c1fa into master Jul 30, 2020
@hhugo hhugo deleted the float-comp branch July 30, 2020 13:01
@hhugo
Copy link
Member

hhugo commented Jul 30, 2020

Thanks for the bugfix

kit-ty-kate pushed a commit to ocaml/opam-repository that referenced this pull request Aug 5, 2020
…ml-ppx, js_of_ocaml-lwt, js_of_ocaml-toplevel, js_of_ocaml-tyxml, js_of_ocaml and js_of_ocaml-ppx_deriving_json (3.7.0)

CHANGES:

## Features/Changes
* Runtime: allow one to override xmlHttpRequest.create (ocsigen/js_of_ocaml#1002)
* Runtime: Change the semantic of MlBytes.toString, introduce MlBytes.toUtf16
* Compiler: initial support for OCaml 4.11
* Compiler: initial support for OCaml 4.12
* Compiler: improve the javascript parser by relying on menhir
  incremental api.
* Compiler: Eliminate allocation of dummy function ocsigen/js_of_ocaml#1013

## Bug fixes
* Compiler: fix code generation for recursive function under for-loops (ocsigen/js_of_ocaml#1009)
* Compiler: the jsoo compiler compiled to javascript was not behaving correctly
            when parsing constant in the from the bytecode
* Compiler: make sure inline doesn't loop indefinitly (ocsigen/js_of_ocaml#1043)
* Compiler: fix bug generating invalid javascript for if-then construct (ocsigen/js_of_ocaml#1046)
* Compiler: do not use polymorphic comparison when joining float values (ocsigen/js_of_ocaml#1048)
* Lib: Rename msg to message in Worker (ocsigen/js_of_ocaml#1037)
* Lib: fix graphics_js when build with separate compilation (ocsigen/js_of_ocaml#1029)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants