[Haskell-cafe] 9.3 - (2 * 4.5) => 0.3000000000000007

Joe Q headprogrammingczar at gmail.com
Wed Jan 16 22:16:39 CET 2013


Welcome to IEEE floating point math!

Wikipedia has a good article on the specification. If you want exact
fractional numbers for your own purposes, there are a number of ways around
the limits of floats.

Rational will represent numbers internally as fractions, and still allow
you to use the same syntax as above. The result will be "3 % 10", which you
read as the fraction 3 / 10.

If you also want irrational numbers, things get tricky. CReal will do it,
but has some limitations.
On Jan 16, 2013 8:26 AM, "ivan dragolov" <ivan at dragolov.net> wrote:

>
> 9.3 - (2 * 4.5) => 0.3000000000000007
>
> I expected 0.3
>
> ?
>
> --
> Иван Драголов
> dragolov.net
>
> GSM: 0888 63 19 46
> GSM за SMS: 0878 82 83 93
> facebook.com/ivan.dragolov
> twitter.com/dragolov
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20130116/4891cb32/attachment.htm>


More information about the Haskell-Cafe mailing list