[Haskell-cafe] [ANN] deka - decimal arithmetic

Omari Norman omari at smileystation.com
Sat Feb 8 21:45:02 UTC 2014

On Sat, Feb 8, 2014 at 4:12 PM, Roman Cheplyaka <roma at ro-che.info> wrote:

> So it is fixed, too? I'm not sure "Fixed" qualifies as a key word, then :)
> Note that Data.Fixed doesn't put any restrictions on the (fixed)
> precision. You could easily define E34.

No, it is not fixed.

>>> digits . unDeka . fromJust . strToDeka $ "3.00"

>>> digits . unDeka . fromJust . strToDeka $ "3.0000"

The precision is determined at runtime.  In contrast, with Data.Fixed, the
programmer sets the precision at compile time.  There is no difference

>>> 3 :: Fixed E6


>>> 3.00 :: Fixed E6

These issues are discussed at


but if your reaction is "so what, it's just some extra zeroes and at
compile time I can just use E34", then by all means, keep using Fixed :)

Also, note that you get 34 significant digits, but that doesn't mean the
exponent is limited to 34.

>>> let x = fromJust . strToDeka $ "3E-200"
>>> let y = fromJust . strToDeka $ "4E-200"
>>> x + y
Deka {unDeka = 7E-200}

...which you could do in Fixed, true.  If you defined E200 first.  But,
oops, now I need E250...

Really this is a binding to decNumber, which implements the General Decimal
Arithmetic Specification, so see if decNumber and that specification
scratch an itch.  If they don't, use Fixed, or Decimal (also on Hackage) or
something else...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20140208/b816928e/attachment.html>

More information about the Haskell-Cafe mailing list