Little errors in number calculations

Hi. I've seen that in GHC sometimes there are little errors in some basic number calculations: *Prelude> 123.35503 * 10.0 1233.5502999999999 *Prelude> properFraction 123.35503 (123,0.3550299999999993) whereas in Hugs no such errors seem to occur (that I have found, at least): *Hugs> 123.35503 * 10.0 1233.5503 (but:) *Hugs> properFraction 123.35503 (123,0.355029999999999) I understand that error may (and will) happen in floating point, but it surprises me that they do so easily, and, above all, the difference between GHC and Hugs. Does someone know why does this difference occur? (Thanks in advance, by the way :) ).

Hello Abby, Sunday, November 15, 2009, 12:00:42 AM, you wrote:
I understand that error may (and will) happen in floating point, but it surprises me that they do so easily, and, above all, the difference between GHC and Hugs. Does someone know why does this difference occur?
compare: 0.355029999999999 0.3550299999999993 hugs just prints one less digit -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

On Sat, Nov 14, 2009 at 09:00:42PM +0000, Abby Henríquez Tejera wrote:
I understand that error may (and will) happen in floating point, but it surprises me that they do so easily, and, above all, the difference between GHC and Hugs. Does someone know why does this difference occur?
The inaccuracy of floating point is the issue; it's just that Hugs sometimes prints things with less precision than required by the Haskell Report, and this can hide the errors.

Abby Henríquez Tejera wrote:
I understand that error may (and will) happen in floating point,
Yes, explained here: http://docs.sun.com/source/806-3568/ncg_goldberg.html
but it surprises me that they do so easily, and, above all, the difference between GHC and Hugs. Does someone know why does this difference occur?
It looks like the two implementations just print floating point numbers with differing amounts of precision (or rather number of digits). Erik -- ---------------------------------------------------------------------- Erik de Castro Lopo http://www.mega-nerd.com/

Hugs is wrong, as you can easily see by evaluating
let x = 123.35503 * 10.0 in x == read (show x)
With ghc it comes out as True and with Hugs as False.
-- Lennart
On Sat, Nov 14, 2009 at 9:00 PM, Abby Henríquez Tejera
Hi.
I've seen that in GHC sometimes there are little errors in some basic number calculations:
*Prelude> 123.35503 * 10.0 1233.5502999999999
*Prelude> properFraction 123.35503 (123,0.3550299999999993)
whereas in Hugs no such errors seem to occur (that I have found, at least):
*Hugs> 123.35503 * 10.0 1233.5503
(but:)
*Hugs> properFraction 123.35503 (123,0.355029999999999)
I understand that error may (and will) happen in floating point, but it surprises me that they do so easily, and, above all, the difference between GHC and Hugs. Does someone know why does this difference occur?
(Thanks in advance, by the way :) ). _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

It's curious that Hugs "lies"...
Thanks for the answers :) .
2009/11/15 Lennart Augustsson
Hugs is wrong, as you can easily see by evaluating let x = 123.35503 * 10.0 in x == read (show x) With ghc it comes out as True and with Hugs as False.
-- Lennart
On Sat, Nov 14, 2009 at 9:00 PM, Abby Henríquez Tejera
wrote: Hi.
I've seen that in GHC sometimes there are little errors in some basic number calculations:
*Prelude> 123.35503 * 10.0 1233.5502999999999
*Prelude> properFraction 123.35503 (123,0.3550299999999993)
whereas in Hugs no such errors seem to occur (that I have found, at least):
*Hugs> 123.35503 * 10.0 1233.5503
(but:)
*Hugs> properFraction 123.35503 (123,0.355029999999999)
I understand that error may (and will) happen in floating point, but it surprises me that they do so easily, and, above all, the difference between GHC and Hugs. Does someone know why does this difference occur?
(Thanks in advance, by the way :) ). _______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
participants (5)
-
Abby Henríquez Tejera
-
Bulat Ziganshin
-
Erik de Castro Lopo
-
Lennart Augustsson
-
Ross Paterson