Skip to content
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

Wrong nan with ocamlc under windows #3490

Closed
vicuna opened this issue Feb 25, 2005 · 2 comments
Closed

Wrong nan with ocamlc under windows #3490

vicuna opened this issue Feb 25, 2005 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 25, 2005

Original bug ID: 3490
Reporter: administrator
Status: closed
Resolution: not a bug
Priority: normal
Severity: minor
Category: ~DO NOT USE (was: OCaml general)

Bug description

Full_Name: Pierre Lemaire
Version: 3.08.2
OS: WindosXP / Linux Debian
Submission from: pierrelemaire.rutcor.rutgers.edu (128.6.29.9)

Hi!

The behavior of Pervasives.compare does not match the specifications, when
using ocamlc under windows XP. Here is a small piece of code:

let test =
Printf.printf "test1: %s\ntest2: %s\n"
(if Pervasives.compare 0.8 nan == 0 then "eq" else "ne")
(if Pervasives.compare nan nan == 0 then "eq" else "ne")
;;

I compiled it with ocamlc (version 3.08.2) under winXP and the output is:
test1: eq
test2: eq
which is obviously wrong in the first case since, according to the
documentation,
"compare treats nan as equal to itself and less than any other float value".

This is all the more a problem, for compatibility reasons, that the behavior
is different if the program is compiled with ocamlc (version 3.08.2 also) under
Linux. Then, the output is, as expected:
test1: ne
test2: eq

I can cope with that by re-defining nan with a dummy (but real) value when I
compile the code under WinXP but, well... that's not exactly nice ;o)

All the best,

Pierre

@vicuna
Copy link
Author

vicuna commented Mar 3, 2005

Comment author: administrator

The behavior of Pervasives.compare does not match the specifications, when
using ocamlc under windows XP. [...]

Let me guess: you used the Windows version of OCaml that was compiled
with Microsoft's compilers, right? Microsoft's "cl" compiler
generates incorrect code (w.r.t. NaN) for floating-point comparisons,
and this causes the behavior of Pervasives.compare that you observed.

There isn't much we can do about it, except abandon the use of
Microsoft's compilers entirely.

You can get the correct results under Windows by using the MinGW or
Cygwin versions of OCaml. gcc does generate correct code for
floating-point comparisons.

  • Xavier Leroy

@vicuna
Copy link
Author

vicuna commented Mar 3, 2005

Comment author: administrator

MSVC code generation error. Not a Caml bug.

@vicuna vicuna closed this as completed Mar 3, 2005
@vicuna vicuna added the bug label Mar 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant