mathr / blog / #

rounded 0.2 and 1.0 released

rounded 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.

The new releases are twofold, v0.x is for MPFR 3.1 or above, and v1.x requires MPFR 4.0 or above. When in doubt, depend on the v0.x branch, because both will be supported for the foreseeable future and there's not that much new in MPFR 4.0 (at least, only two additional functions are exposed by rounded so far, though that may increase).

The main changes versus the previous release are bindings for a lot more of the MPFR API (I think all unary functions and binary functions are included now). There are still functions missing, mostly those with less common types, so pull requests adding them are welcome. There is also a fix to a memory corrupting crash in the long-double support: a foreign function was imported with an argument missing so the pointer used to write flags to was running wild.

rounded was originally written around 7 years ago by Edward Kmett and Daniel Peebles, but it couldn't be made to work properly until GHC's integer-gmp implementation was changed later (something to do with GMP custom memory allocation vs GHC's garbage collector). I did the work to rip out the semi-broken C-- code and replace it with a more straight-forward (though perhaps less performant) Foreign Function Interface (FFI) binding, and took over the maintainership about a year ago.

You can get it from Hackage or Github, and I have a mirror of the repository on my own code hosting.