Correctly-rounded arbitrary-precision floating-point arithmetic

Version on this page:
LTS Haskell 12.22:
Stackage Nightly 2018-12-14:
Latest on Hackage:

See all snapshots rounded appears in

BSD3 licensed by Edward A. Kmett, Daniel G. Peebles, Claude Heiland-Allen
Maintained by Claude Heiland-Allen

Module documentation for

There are no documented modules for this package.


Build Status

This package provides properly rounded floating point numbers of arbitrary precision. It does so by wrapping the GNU MPFR library.

Phantom types carry the information about the precision and rounding mode, letting you treat properly rounded floating point numbers as instances of Num or Floating, like any other numeric type in Haskell.

Unlike other attempts to port MPFR to Haskell, this library does not require you to cripple Integer performance or link your code in an unnatural way.


{-# LANGUAGE DataKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
import Numeric.Rounded
import Data.Proxy

To use a 53 bit significand (the same size as used by a Double), and round down intermediate results:

>>> pi :: Rounded TowardZero Double

We can also round away from zero, or use other rounding modes.

>>> pi :: Rounded AwayFromZero Double

We can specify the significand size directly using type literals in GHC:

>>> kCatalan :: Rounded TowardZero 128

You can also specify a dynamic significand size at runtime:

>>> reifyPrecision 512 (\(_ :: Proxy p) -> show (logBase 10 2 :: Rounded TowardNearest p))

or a dynamic rounding mode:

ghci> reifyRounding TowardZero (\(_ :: Proxy r) -> show (logBase 10 2 :: Rounded r 512))

Contact Information

Please, feel free to contact me with questions, concerns, or bug fixes.

I can be reached as ekmett via github or as edwardk on the #haskell IRC channel on

-Edward Kmett


Revision history for rounded – 2018-10-31

  • License changed from LGPL to BSD3.

0.1 – 2018-10-30

  • Bindings rewritten as a straight FFI binding without a patched MPFR.
  • Added Simple module.


  • Repository initialized based on older work on a package called precision
  • Daniel Peebles was able to get a patched MPFR to work
Depends on 6 packages:
Used by 2 packages:
comments powered byDisqus