You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Original bug ID: 4161 Reporter: schneck Status: closed (set by @damiendoligez on 2006-11-15T11:18:50Z) Resolution: won't fix Priority: normal Severity: minor Version: 3.09.0 Category: ~DO NOT USE (was: OCaml general) Duplicate of:#4025
Bug description
Earlier I posted a bug mentioning floating point problems with native code on an Intel Mac; the same problems arise in Windows. Startling that no one else has noticed this! It leads to different behaviors in real programs, but here are some toy examples. Many of them have to do with optimizations, but one shows an actual different result from a single division.
let print x =
print_endline (Int64.to_string (Int64.bits_of_float x))
let bug_1 () =
let x = 1. /. 3. in
let y = 1. /. 2. in
print (x /. (x +. y));
let (/.) = (/.) in
print (x /. (x +. y))
let bug_2 () =
let x = 0.75 in
let y = 0.3 in
let z = 0.05 in
print ((x *. y) /. z);
let (/.) = (/.) in
print ((x *. y) /. z)
let bug_3 () =
let a = 0.1 in
let x = 0.0005 in
let y = 4. /. 900. in
print (x +. (1. -. a) *. y);
let ( *. ) = ( *. ) in
print (x +. (1. -. a) *. y)
let bug_4 () =
let x = Int64.float_of_bits (Int64.of_string "4600105333671292343") in
let y = Int64.float_of_bits (Int64.of_string "4607182418800017407") in
print (x *. y +. (1. -. x));
let (+.) = (+.) in
print (x *. y +. (1. -. x))
let bug_5 () =
let a = 0.5 in
let b = Int64.float_of_bits (Int64.of_string "4607182418800017407") in
print (a /. b)
Original bug ID: 4161
Reporter: schneck
Status: closed (set by @damiendoligez on 2006-11-15T11:18:50Z)
Resolution: won't fix
Priority: normal
Severity: minor
Version: 3.09.0
Category: ~DO NOT USE (was: OCaml general)
Duplicate of: #4025
Bug description
Earlier I posted a bug mentioning floating point problems with native code on an Intel Mac; the same problems arise in Windows. Startling that no one else has noticed this! It leads to different behaviors in real programs, but here are some toy examples. Many of them have to do with optimizations, but one shows an actual different result from a single division.
(*
ocamlopt -o intel_bugs intel_bugs.ml
./intel_bugs
ocamlc -o intel_bugs.byte intel_bugs.ml
./intel_bugs.byte
4600877379321698713
4600877379321698714
4616752568008179712
4616752568008179711
4571838168924413755
4571838168924413756
4607182418800017408
4607182418800017407
4602678819172646912
4600877379321698714
4600877379321698714
4616752568008179711
4616752568008179711
4571838168924413756
4571838168924413756
4607182418800017407
4607182418800017407
4602678819172646913
*)
let print x =
print_endline (Int64.to_string (Int64.bits_of_float x))
let bug_1 () =
let x = 1. /. 3. in
let y = 1. /. 2. in
print (x /. (x +. y));
let (/.) = (/.) in
print (x /. (x +. y))
let bug_2 () =
let x = 0.75 in
let y = 0.3 in
let z = 0.05 in
print ((x *. y) /. z);
let (/.) = (/.) in
print ((x *. y) /. z)
let bug_3 () =
let a = 0.1 in
let x = 0.0005 in
let y = 4. /. 900. in
print (x +. (1. -. a) *. y);
let ( *. ) = ( *. ) in
print (x +. (1. -. a) *. y)
let bug_4 () =
let x = Int64.float_of_bits (Int64.of_string "4600105333671292343") in
let y = Int64.float_of_bits (Int64.of_string "4607182418800017407") in
print (x *. y +. (1. -. x));
let (+.) = (+.) in
print (x *. y +. (1. -. x))
let bug_5 () =
let a = 0.5 in
let b = Int64.float_of_bits (Int64.of_string "4607182418800017407") in
print (a /. b)
let _ =
bug_1 ();
bug_2 ();
bug_3 ();
bug_4 ();
bug_5 ()
The text was updated successfully, but these errors were encountered: