Monthly Downloads: 26
Programming language: Haskell
License: Apache License 2.0
Tags: Math    

HasBigDecimal alternatives and similar packages

Based on the "Math" category.
Alternatively, view HasBigDecimal alternatives based on common mentions on social networks and blogs.

Do you think we are missing an alternative of HasBigDecimal or a related project?

Add another 'Math' Package


Build Status


This module defines the type 'BigDecimal' which provides a representation of arbitrary precision decimal numbers. 'BigDecimal' is a native Haskell implementation based on arbitrary sized 'Integer' values. The implementation was inspired by Java BigDecimals.

BigDecimal instantiates the typeclasses 'Num', 'Fractional' and 'Real'. It is thus possible to use all common operators like '+', '-', '*', '/', '' on them.

Some examples from a ghci REPL

λ> a = BigDecimal 144 2
λ> toString a
λ> b = sqrt a
λ> toString b
λ> b * b
BigDecimal 144 2
λ> b * b * b
BigDecimal 1728 3
λ> b^2
BigDecimal 144 2
λ> c = fromString "123.4567890"
λ> c
BigDecimal 1234567890 7
λ> a / c
BigDecimal 1166400010614240096589584878965222398584 41
λ> roundBD it (halfUp 10)
BigDecimal 116640001 10
λ> divide (a, c) $ halfUp 20
BigDecimal 1166400010614240097 20


in addition to the pretty complete BigDecimal module there is the rather scetchy BigFloating module. BigFloating contains a few first step to let BigDecimal instantiate the Floating typeclass. As of now it contains arbitrary precision implementations for pi (based on Chudnovskis algorithm), sqrt and nthroot (based on Newtons classic algorithm). All trigonometric functions, log and exp are still missing. All code contributions are most welcome! Here are some working examples:

λ> r = sqrt (BigDecimal 2 0)
λ> toString r
λ> r^2*pi
BigDecimal 6283185307179586476925286766559005768394338798750211641949889184615632812572417997256069650684234135488875159962758271904785109490094314219117662951460673928547017151357805018682925970564827587058974690236729643325013696514697383143361638452329945607739055327681644609147889519349178329780951524191191 300
λ> toString it

λ>  sqr 2 (halfUp 50)
BigDecimal 141421356237309504880168872420969807856967187537695 50
λ>  sqr 2 (halfUp 500)
BigDecimal 141421356237309504880168872420969807856967187537694807317667973799073247846210703885038753432764157273501384623091229702492483605585073721264412149709993583141322266592750559275579995050115278206057147010955997160597027453459686201472851741864088919860955232923048430871432145083976260362799525140798968725339654633180882964062061525835239505474575028775996172983557522033753185701135437460340849884716038689997069900481503054402779031645424782306849293691862158057846311159666871301301561856898723724 500