Giter VIP home page Giter VIP logo

ocaml-decimal's Introduction

decimal

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

Opam: https://opam.ocaml.org/packages/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

$ 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
# (* round to decimal places: *)
  D.(round ~n:2 (of_int 22 / of_int 7));;
- : D.t = 3.14

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

ocaml-decimal's People

Contributors

yawaramin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.