Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
MPFR bindings for Haskell
Haskell C
branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
cbits updated copyright
deps/mpfr-3.1.2 Make it build again up to the cmm point (it was missing some valuable…
src/Numeric fixed properFraction -- based on code by Claude Heiland-Allen
.gitignore Fixed sandbox compatibility
.travis.yml use travis_retry and pull happy
CHANGELOG.markdown release notes, tested-with ghc 7.8.4
Setup.hs Fixed sandbox compatibility
rounded.cabal release notes, tested-with ghc 7.8.4



Build Status

This package provides properly rounded floating point numbers of arbitrary precision.

It does so by wrapping the GNU MPFR library. However, it actually contains a patched copy of MPFR 3.1.0, which has been updated to be compatible with GHC's use of GMP's garbage collection hook.

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 #-}
import Numeric.Rounded

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

Something went wrong with that request. Please try again.