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: 6835 Reporter: igo_weiqi_baduk Status: closed (set by @xavierleroy on 2016-12-07T10:47:29Z) Resolution: not a bug Priority: normal Severity: minor Platform: x86_64 OS: Mageia 4 Version: 4.02.1 Category: standard library
Bug description
Using exponential function for some computations I've got :
let n1 = 2. ** 100. ;;
val n1 : float = 1.2676506002282294e+30
let n2 = 2. ** 47. ;;
val n2 : float = 140737488355328.
let n3 = 2. ** 48. ;;
val n3 : float = 281474976710656.
(n1 +. n2) -. n1 ;;
: float = 0. <---- ???
(n1 +. n3) -. n1 ;;
: float = 281474976710656. <---- OK
In this example, why is n2 completely ignored (and not n3) ?
If this behavior is "correct" , what are the recommended
operations to do in order to get a right result ?
( apart ,of course, writing n1 -. n1 +. n2 which gives the right result
hopefully, but well, this is only a very basic example ).
Rem : with the Num library , all is right
open Num
let num1 = (Int 2 **/ Int 100) ;;
val n1 : Num.num = <num 1267650600228229401496703205376>
let num2 = (Int 2 **/ Int 47) ;;
val n2 : Num.num = <num 140737488355328>
(num1 +/ num2) -/ num1 ;;
: Num.num = <num 140737488355328>
The text was updated successfully, but these errors were encountered:
Remember that the only integers that can be exactly represented by double floating point numbers are those in the interval [-2^53;2^53].
n1 is much larger than that and it so happens that n1 + n2 is represented by n1 while n1 + n3 is not. It also happens that n1 + n3 is precisely represented. But for example n3 + 1 is not:
let n4 = n3 +. 1.;;
val n4 : float = 281474976710657.
(n1 +. n4) -. n1 ;;
: float = 281474976710656. <----- n3 !
You are just witnessing floating point arithmetic precision errors.
Original bug ID: 6835
Reporter: igo_weiqi_baduk
Status: closed (set by @xavierleroy on 2016-12-07T10:47:29Z)
Resolution: not a bug
Priority: normal
Severity: minor
Platform: x86_64
OS: Mageia 4
Version: 4.02.1
Category: standard library
Bug description
Using exponential function for some computations I've got :
let n1 = 2. ** 100. ;;
val n1 : float = 1.2676506002282294e+30
let n2 = 2. ** 47. ;;
val n2 : float = 140737488355328.
let n3 = 2. ** 48. ;;
val n3 : float = 281474976710656.
(n1 +. n2) -. n1 ;;
(n1 +. n3) -. n1 ;;
In this example, why is n2 completely ignored (and not n3) ?
If this behavior is "correct" , what are the recommended
operations to do in order to get a right result ?
( apart ,of course, writing n1 -. n1 +. n2 which gives the right result
hopefully, but well, this is only a very basic example ).
Rem : with the Num library , all is right
open Num
let num1 = (Int 2 **/ Int 100) ;;
val n1 : Num.num = <num 1267650600228229401496703205376>
let num2 = (Int 2 **/ Int 47) ;;
val n2 : Num.num = <num 140737488355328>
(num1 +/ num2) -/ num1 ;;
The text was updated successfully, but these errors were encountered: