Floating point problems
Lennart Augustsson
lennart at augustsson.net
Wed Aug 30 18:09:22 EDT 2006
Slightly tongue in cheek, I think the real problem is that your
courses come in the wrong order. No one should use floating point
numbers without first having a course in numerical analysis. :)
-- Lennart
On Aug 30, 2006, at 14:38 , Jamie Brandon wrote:
> I recently defied my supervisor and used Haskell to write my
> coursework
> instead of C. All went well until I needed floating point and
> started having odd results. As far as I can tell it isn't
> substantially affecting my results but it is rather embarrassing after
> slagging off C so much. Here are some examples:
>
> *Main> 0.2 + 0.1
> 0.30000000000000004
> *Main> 0.200000000000000 + 0.100000000000000000
> 0.30000000000000004
> *Main> 0.3 + 0.1
> 0.4
> *Main> 0.2 + 0.1
> 0.30000000000000004
> *Main> it + 0.1
> 0.4
>
> I assume this is a result of the discrepancy between binary and
> decimal
> representations of the numbers. Is there any way around? For a
> start, it
> would be nice to have a simple way to get 0.1 + 0.2 == 0.3 = True
>
> This is with GHC 6.4.1 and GCC 4.0.3
>
> Thanks, Jamie
>
> _______________________________________________
> Glasgow-haskell-users mailing list
> Glasgow-haskell-users at haskell.org
> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
More information about the Glasgow-haskell-users
mailing list