[Haskell-beginners] ghci: inconsistent return values for succ

Dan Stromberg strombrg at gmail.com
Sun Oct 18 02:21:47 UTC 2015


On Sat, Oct 17, 2015 at 7:17 PM, Frothy Bits <neuralpancake at gmail.com>
wrote:

> Greetings,
>
> Absolutely brand new to Haskell.  Taking ghci v7.10.2 out for a spin, and
> I find I get inconsistent return values for succ n:
>
> ghci> succ 3.14
> 4.1400000000000001
>
> for example instead of the expected 4.14
>

This is pretty standard for today's floating point hardware in CPU's.  It's
not a Haskell thing.  It comes up in C and Python too - that is, in pretty
much anything that uses hardware floating point.

If you need precision, try an integral type or a rational.

-- 
Dan Stromberg
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20151017/50fad120/attachment.html>


More information about the Beginners mailing list