From: "M. Edward (Ed) Borasky" Date: 2007-09-01T02:06:07+09:00 Subject: Re: 0.06 == 0.06 returns false in Ruby? -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Ken Bloom wrote: > On Sat, 01 Sep 2007 00:24:39 +0900, M. Edward (Ed) Borasky wrote: >> Kyle Schmitt wrote: >>> On 8/30/07, doug meyer wrote: >>>> There is also a class called BigDecimal (or something like that) if >>>> you want to have really accurate numbers and no floating-point errors. >>> A warning on things like BigDecimal. >>> Unless I'm mistaken it's still stored in twos compliment, which means >>> you'll still end up with the same sort of floating point problems >>> (albeit further down), and the same numbers that you can't express >>> exactly with a normal float, can't be expressed exactly with a >>> BigDecimal. >>> >>> You'd think some fixed point math libraries would help, but be careful, >>> because many of those _also_ store in twos compliment. >>> >>> --Kyle >>> >>> >> IIRC BigDecimal is in fact stored in (pregnant pause) Binary Coded >> Decimal. But I should check that. > > Neither one can represent 1/3 or sqrt(2) exactly. > Which is why there are libraries and packages like GiNaC, CLN, GMP, Singular, Maxima, Axiom, ... I personally think Ruby's libraries for exact arithmetic are better than those in the other scripting languages -- I don't think anyone else has BigDecimal, Rational, Complex, Matrix, "mathn" and Bignums built in or part of the *standard* libraries. The only thing that's missing, as I noted earlier, is the ability to declare a physically contiguous block of RAM as a vector of floating point or complex numbers and operate on them as such. For that, you need to go to an external package like NArray. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD4DBQFG2Ept8fKMegVjSM8RAiqFAJi/iWlXdhu/4UNm8y3WV+g6tlaCAKC5PDDS yWzL3Cnk6zkYnMcA/Rl4dw== =bW0a -----END PGP SIGNATURE-----