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

Floating-point difference between ocamlc and ocamlopt #2480

Closed
vicuna opened this issue Apr 18, 2004 · 2 comments
Closed

Floating-point difference between ocamlc and ocamlopt #2480

vicuna opened this issue Apr 18, 2004 · 2 comments
Labels

Comments

@vicuna
Copy link

vicuna commented Apr 18, 2004

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

Bug description

Full_Name: Shawn Wagner
Version: 3.07
OS: Linux x86
Submission from: dialup-4.242.105.156.dial1.seattle1.level3.net (4.242.105.156)

ocamlopt doesn't seem to handle literal negative 0. values properly.

The following program:

let signbit x = Int64.shift_right_logical (Int64.bits_of_float x) 63 =
Int64.one
and zero = -0.0 in
Printf.printf "zero = %f and signbit zero = %b\n" zero (signbit zero)

will output 'zero = -0.000000 and signbit zero = true' when compiled with ocamlc
but 'zero = 0.000000 and signbit zero = false' when compiled with ocamlopt. The
negative sign's getting dropped somewhere.

peers at the source

It looks like the problem is in asmcomp/i386/emit.mlp in emit_instr in the
section that matches Lop(Iconst_float s). It compares the constant to 0.0 and
emits a fldz instruction. Since -0.0 and 0.0 are equal, it looses the signbit
there.

@vicuna
Copy link
Author

vicuna commented Apr 18, 2004

Comment author: administrator

Some more playing around produces this patch, which fixes the problem for
x86. I assume that all the native-code targets have the same issue, though.

*** asmcomp/i386/emit.mlp.orig Sun Apr 18 15:27:32 2004
--- asmcomp/i386/emit.mlp Sun Apr 18 16:05:11 2004


*** 400,408 ****
movl ${emit_nativeint n}, {emit_reg i.res.(0)}\n
| Lop(Iconst_float s) ->
let f = float_of_string s in
! if f = 0.0 then
! fldz\n
! else if f = 1.0 then
fld1\n
else begin
let lbl = new_label() in
--- 400,412 ----
movl ${emit_nativeint n}, {emit_reg i.res.(0)}\n
| Lop(Iconst_float s) ->
let f = float_of_string s in
! if f = 0.0 then begin
! if Int64.shift_right_logical (Int64.bits_of_float f) 63 = Int64.zero
! then (* +0.0 )
! fldz\n
! else (
-0.0 *)
! fldz\n fchs\n
! end else if f = 1.0 then
fld1\n
else begin
let lbl = new_label() in

@vicuna
Copy link
Author

vicuna commented May 3, 2004

Comment author: administrator

Fixed by XL 2004-05-03.

@vicuna vicuna closed this as completed May 3, 2004
@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