Possible Duplicate:
Is JavaScript's Math broken?
I have fount weird problem in arithmetic precision in OCaml. Look:
# 1.1+.2.2;;
- : float = 3.30000000000000027
It happen only when I do: something.1 + something.2. Could someone try it?
Possible Duplicate:
Is JavaScript's Math broken?
I have fount weird problem in arithmetic precision in OCaml. Look:
# 1.1+.2.2;;
- : float = 3.30000000000000027
It happen only when I do: something.1 + something.2. Could someone try it?
This is a reality of using floating-point values. While 1.1 is represented exactly in decimal with two digits, it takes an infinite number of binary digits to represent this value. Since you are are storing 1.1 in binary with a finite number of bits, rounding error occurs.
Ocaml float numbers are IEEE754 double precision numbers. You'll have the same behavior in other programming languages. Perhaps you want floating bignums (which Ocaml don't provide).
A computer has always finite precision native numbers (much like a calculator).