--------------enig36EC0771B2612EAB387A253F
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

Jeremy Tregunna wrote:
>> Actually, integers are more precise than IEEE floating points
>> since 2.2 - 1.2 != 1.0 :) s/precise/accurate !
> 
> Not on all platforms. For instance, in Ocaml, it's true:
> 
> # 2. -. 1. = 1.;;
> - : bool = true
> 

Your example works because integers are rational IEEE floating point
numbers. Problems arise when you use a number that's a rational decimal
number, but an irrational IEEE binary floating point one. Those aren't
precise no matter what storage size you use.

# 2.2 -. 1.2;;
- : float = 1.0000000000000002
# (2.2 -. 1.2) != 1.0;;
- : bool = true

For this example, Ruby's rounding earlier loses the imprecision.

Ripping off a tutorial article on IEEE floats[1] produces an example
that manifests in Ruby (also in OCaml):

irb(main):001:0> a = 0.0
=> 0.0
irb(main):002:0> 10000.times {
irb(main):003:1*   a += 0.0001
irb(main):004:1> }
=> 10000
irb(main):005:0> a
=> 0.999999999999906
irb(main):006:0>

David Vallner

[1] http://support.microsoft.com/default.aspx?scid=kb;EN-US;q42980


--------------enig36EC0771B2612EAB387A253F
Content-Type: application/pgp-signature; name="signature.asc"
Content-Description: OpenPGP digital signature
Content-Disposition: attachment; filename="signature.asc"

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (MingW32)

iD8DBQFFHrWly6MhrS8astoRAitAAJwJSZxvTwqKGraKwoxLVnwxIgzbWQCffXCj
rizPem9shLANFmM4J9oOVjgfZ
-----END PGP SIGNATURE-----

--------------enig36EC0771B2612EAB387A253F--