package decimal

All checked builds pass
  1. Overview
  2. Docs
Arbitrary-precision floating-point decimal library

Install

dune-project
 Dependency

Authors

Maintainers

Sources

decimal-1.0.2.tbz
sha256=39ba0f5b8f0c6943422ca08b26ea37c0aa4fdfacd29a40d9c195d48f5513fe6c
sha512=6157fccb1149e255897b7aa3f58ba33bb3a01c8c0a048f0f315325bd4bf4ef30b580e506c69c05c24e292f602409f0e21f9796d49a2c1bc3a20200d30faa3c56

Description

Arbitrary-precision floating-point decimal library ported from the Python decimal module.

Added to opam-repository:

README

decimal

Arbitrary-precision floating-point decimal type implemented in OCaml. Ported from Python decimal module. It uses Zarith to do biginteger arithmetic.

Opam: https://ocaml.org/p/decimal

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

See next section (below) for dune instructions.

    $ opam install decimal # if trying out
# (* if trying out: *)
  #require "decimal";;
  #require "ppx_decimal";;
# (* tell the REPL how to display decimals *)
  #install_printer Decimal.pp;;
# (* PPX gives convenience literal syntax *)
  Decimal.(0.1m + 0.2m);;
- : Decimal.t = 0.3
# (* default precision is 32 *)
  Decimal.(of_int 1 / of_int 3);;
- : Decimal.t = 0.33333333333333333333333333333333
# (* round to decimal places: *)
  Decimal.(round ~n:2 (of_int 22 / of_int 7));;
- : Decimal.t = 3.14

Use with dune

In your dune file's executable or similar stanza:

 (libraries decimal)
 (preprocess (pps ppx_decimal))

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
git show ae0196377fb7a99db7f198f2fb242e6a2fe4541e | git apply

Dependencies (3)

  1. zarith >= "1.10" & < "2.0.0"
  2. ocaml >= "4.08.0"
  3. dune >= "2.7"

Dev Dependencies (3)

  1. odoc with-doc
  2. angstrom >= "0.15.0" & < "1.0.0" & with-test
  3. alcotest >= "1.5.0" & < "2.0.0" & with-test

Optional Dependencies

None

Used by (1)

  1. ppx_decimal >= "1.0.2"

Conflicts

None

Build status

Results of building decimal with each compiler on check.ci.ocaml.org, run of against opam-repository 8a77e58. All results for this package.

Each result links to its build log. To keep crawlers from overloading the site, build logs require a GitHub sign-in (see ocurrent/opam-health-check). On your first log, GitHub asks you to “Authorize opam-health-check”, the OCurrent app that runs these checks; it sees only your public profile, not your repositories. The sign-in lasts 30 days.

Version OCaml 4.11 OCaml 4.14 OCaml 5.2 OCaml 5.4 OCaml 5.5
1.0.2 (this version) good good good good good
  • good Package successfully built
  • partial One of the dependencies failed to build
  • bad Package failed to build
  • n/a Package is not available in this environment
  • internal Internal failure