[Haskell-cafe] Accuracy of Data.Number.Fixed

Lyle Kopnicky lists at qseep.net
Sat Mar 5 03:50:55 UTC 2016


This does not seem right to me:

Prelude Data.Number.Fixed> read "4.00" :: Fixed (EpsDiv10 (EpsDiv10 Eps1))
4.00
Prelude Data.Number.Fixed> read "4.01" :: Fixed (EpsDiv10 (EpsDiv10 Eps1))
4.00
Prelude Data.Number.Fixed> read "4.02" :: Fixed (EpsDiv10 (EpsDiv10 Eps1))
4.03
Prelude Data.Number.Fixed> read "4.03" :: Fixed (EpsDiv10 (EpsDiv10 Eps1))
4.04
Prelude Data.Number.Fixed> read "4.04" :: Fixed (EpsDiv10 (EpsDiv10 Eps1))
4.05

Maybe I am misunderstanding the purpose of this library. I guess that "two
digits" of precision means that it is accurate within +/- 0.01?

I think that this library is meant for doing arbitrary-precision
transcendental operations. But it would not be good as a model for
something like currency.

It's using ratios as an internal representation, and I'm not sure what
ratios it's choosing, but I think I'd choose, say, 401/100 for the "4.01"
representation. I guess it's picking a slightly smaller factor than that.

The non-reversibility of read/show is somewhat disconcerting. I think I
prefer the Decimal library for currency.

Regards,
Lyle
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20160304/cb2561fa/attachment.html>


More information about the Haskell-Cafe mailing list