package decimal
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=c100880fa853ae34e07c9a701a2530d8185119fc3b34b7d6125c83b93373747a
sha512=8130534fb3321d315031723d3fcb9846bec4031e5ec893b6e4a9455b8d396f190ffd9c29e8bf7f47e3d37e232d078df98976cf77965e0296e4a9daac25f02d66
Description
Arbitrary-precision floating-point decimal library ported from the Python decimal module.
Published: 21 Nov 2020
README
decimal
Arbitrary-precision floating-point decimal type implemented in OCaml. Ported from Python decimal
module. It uses Zarith to do biginteger arithmetic.
License
This package is licensed under the Python Software Foundation License v2, for the sake of simplicity, as it is a derived work of the Python decimal
module.
Examples
$ opam install decimal # if trying out
# (* if trying out: *)
#require "decimal";;
# (* for convenience *)
module D = Decimal
let i = D.of_int
let s = D.of_string;;
# (* tell the REPL how to display decimals *)
#install_printer D.pp;;
#
D.(s "0.1" + s "0.2");;
- : D.t = 0.3
# (* default precision is 32 *)
D.(i 1 / i 3);;
- : D.t = 0.33333333333333333333333333333333
Dev
Build:
dune build
Try in REPL:
dune utop
Tests
The test runner source is in test/decimal_test.ml
. It parses and runs the test cases in test/data/
. I am adding test case data files from the Python snapshot as I go.
Run current tests:
dune test
Note that, some of the tests don't make sense for the OCaml port and have thus been deleted. If you ever need to update to new versions of the test files, you can apply the changes as patches after re-dowloading the relevant *.decTest
files:
git show 07074859567e936b8d170aba5ef58889a4d9d467 | git apply