MPFR bindings for Haskell
Haskell C
Switch branches/tags
Nothing to show



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