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

This is a package candidate release! Here you can preview how this package release will appear once published to the main package index (which can be accomplished via the 'maintain' link below). Please note that once a package has been published to the main package index it cannot be undone! Please consult the package uploading documentation for more information.

[maintain] [Publish]

This package provides numeric instances for MPFR that use "Implicit Configurations" from http://www.cs.rutgers.edu/~ccshan/prepose/prepose.pdf 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
23.140692632779269005729086367948547380266106242600211993445046409524342350690452783516971997067549219675952704801087773144428044414693835844717445879609842

[Skip to Readme]

Properties

Versions 0.1, 0.1, 0.1.0.1, 0.2, 0.3, 1.0, 1.1, 1.1.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 && <0.2), reflection (>=2.1.2 && <2.2), singletons (>=2.1 && <2.6) [details]
License LicenseRef-LGPL
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 <claude@mathr.co.uk>
Category Numeric, Math
Home page https://github.com/ekmett/rounded
Bug tracker https://github.com/ekmett/rounded/issues
Source repo head: git clone git://github.com/ekmett/rounded.git
this: git clone git://github.com/ekmett/rounded.git(tag rounded-0.1)
Uploaded by ClaudeHeilandAllen at 2018-10-30T16:45:39Z

Modules

[Index] [Quick Jump]

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees


Readme for rounded-0.1

[back to package description]

rounded

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.

Usage

{-# 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
3.141592653589793

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

>>> pi :: Rounded AwayFromZero Double
3.1415926535897936

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

>>> kCatalan :: Rounded TowardZero 128
0.915965594177219015054603514932384110773

You can also specify a dynamic significand size at runtime:

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

or a dynamic rounding mode:

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

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 irc.freenode.net.

-Edward Kmett