rounded: Correctly-rounded arbitrary-precision floating-point arithmetic

[ bsd3, library, math, numeric ] [ Propose Tags ]

This package provides numeric instances for MPFR that use "Implicit Configurations" from to choose a Rounding and Precision. For those that do not want to use reflection, explicit instances are provided for common precisions and for the built-in rounding modes.

This package should work correctly with GHC 7.10.1 or later.

>>> import Numeric.Rounded
>>> :set -XDataKinds
>>> exp pi :: Rounded TowardZero 512

[Skip to Readme]
Versions [faq] 0.1,
Change log CHANGELOG.markdown
Dependencies base (>=4.8 && <4.13), ghc-prim (>=0.4 && <0.6), hgmp (>=0.1.1 && <0.2), long-double (==0.1.*), reflection (>=2.1.2 && <2.2), singletons (>=2.1 && <2.6) [details]
License BSD-3-Clause
Copyright Copyright (C) 2012-2014 Edward A. Kmett, Daniel G. Peebles; Copyright (C) 2013-2018 Claude Heiland-Allen
Author Edward A. Kmett, Daniel G. Peebles, Claude Heiland-Allen
Maintainer Claude Heiland-Allen <>
Category Numeric, Math
Home page
Bug tracker
Source repo head: git clone git://
this: git clone git:// rounded-
Uploaded by ClaudeHeilandAllen at Wed Oct 31 18:01:30 UTC 2018
Distributions LTSHaskell:, NixOS:
Downloads 140 total (53 in the last 30 days)
Rating (no votes yet) [estimated by rule of succession]
Your Rating
  • λ
  • λ
  • λ
Status Hackage Matrix CI
Docs available [build log]
Last success reported on 2018-11-02 [all 1 reports]


[Index] [Quick Jump]


Maintainer's Corner

For package maintainers and hackage trustees

Readme for rounded-

[back to package description]


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