Reputation: 62848
Haskell has a built-in Integer
type, which handles arbitrary-precision integers. There is also Rational
, which is an arbitrary-precision fraction. But arithmetic on such things requires finding a common denominator, and then cancelling the result down to least terms.
What if I wanted to do floating-point arithmetic with (say) 100 bits of precision in the mantissa? How would I do that?
I see there's a Data.Fixed
module, but that seems to provide a handful of custom-written types with fixed precision. What I want is something where I can dynamically increase or decrease precision at run-time, according to how much accuracy is required for each task.
PS. I'm not looking for decimal arithmetic, although I suppose it would be interesting to know whether that's available somewhere...
Upvotes: 8
Views: 362
Reputation: 23014
Try Data.Number.CReal
from the numbers package. It gives you the precision you ask for when converting to a string.
Upvotes: 4
Reputation: 1
How about http://hackage.haskell.org/package/numbers-2009.8.9/docs/Data-Number-BigFloat.html ? In this BigFloat data type you choose precision on your own. I know it's decimal, but maybe you can easily change it to binary
Upvotes: 0