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

[Bug] Different behavior bytecode/nativecode #3495

Closed
vicuna opened this issue Feb 27, 2005 · 1 comment
Closed

[Bug] Different behavior bytecode/nativecode #3495

vicuna opened this issue Feb 27, 2005 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented Feb 27, 2005

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

Bug description

Hi,

When I compile the attached program to bytecode, I get the output
"0.000000 -1.000000 -> 1" (which is correct) but when I compile to
native code the result is "0.000000 -1.000000 -> 0".

The error stops when I substitute "invw" in "let cr = 300. *. invw
-. 1.5" by its definition (i.e. if I write
"let cr = 300. *. (2. /. float w) -. 1.5").

Curious to know what is the problem.

Cheers,
ChriS


let niter = 50
let limit = 2.

let limit2 = limit *. limit

let add_bit0 cr ci byte =
let rec loop i zr zi =
if zr *. zr +. zi *. zi > limit2 then (byte lsl 1) lor 0x00
else if i > niter then (byte lsl 1) lor 0x01
else loop (i + 1) (zr *. zr -. zi *. zi +. cr) (2. *. zr *. zi +. ci) in
loop 1 0. 0.

let () =
let w = 400 in
let invw = 2. /. float w in
let ci = -1. in
let cr = 300. *. invw -. 1.5 in
Printf.printf "%f %f -> %i\n" cr ci (add_bit0 cr ci 0);



@vicuna
Copy link
Author

vicuna commented Mar 3, 2005

Comment author: administrator

Numerical instability. ocamlopt computes intermediate float results with higher
precision. Issue is documented in the manual.

@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