
Hello I was wondering if there is a bug in GHC 6.10.1 regarding number precision. As an example, in GHCi with:
3.0 * 0.2
I get: 0.6000000000000001 Although:
2.0 * 0.2 0.4
I have GHC 6.10.1 on Mac OS X 10.5. Is this a known bug or should I report it? Best regards Zé Pedro

Hi, Floating point numbers are just inaccurate, so the results you see aren't too surprisingly. Interestingly enough, using Hugs, I get the right answer in both cases - so its possible it's a bug, but unlikely. If you do want exact floating point manipulation then use rational numbers instead, for example:
3.0 * 0.2 :: Rational 3%5
Which should be read as a fraction, 3/5, which is the right answer. Thanks Neil
-----Original Message----- From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@haskell.org] On Behalf Of José Pedro Correia Sent: 14 November 2008 2:33 pm To: glasgow-haskell-users@haskell.org Subject: Re: Bug in GHC6.10.1?
Hello
I was wondering if there is a bug in GHC 6.10.1 regarding number precision.
As an example, in GHCi with:
3.0 * 0.2
I get: 0.6000000000000001
Although:
2.0 * 0.2 0.4
I have GHC 6.10.1 on Mac OS X 10.5.
Is this a known bug or should I report it?
Best regards Zé Pedro _______________________________________________ Glasgow-haskell-users mailing list Glasgow-haskell-users@haskell.org http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ==============================================================================

On Fri, 2008-11-14 at 14:43 +0000, Mitchell, Neil wrote:
Hi,
Floating point numbers are just inaccurate, so the results you see aren't too surprisingly.
Interestingly enough, using Hugs, I get the right answer in both cases - so its possible it's a bug, but unlikely.
Hugs probably just rounds more. hugs: 0.6 irb: 0.6 ghci: 0.6000000000000001 python: 0.60000000000000009 ocaml: 0.600000000000000089 Duncan

Hello José, Friday, November 14, 2008, 5:32:52 PM, you wrote:
0.6000000000000001
computers store floating-point numbers in binary form, and it's imposiible to represent 3/5 in binary form exactly for the same reasons as impossibility to represent 1/3 exactly in decimal form (sorry for awkward english) -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com
participants (4)
-
Bulat Ziganshin
-
Duncan Coutts
-
José Pedro Correia
-
Mitchell, Neil