package bigdecimal
Install
Dune Dependency
Authors
Maintainers
Sources
sha256=6b9b935460f904d6955ade682446f91fd6223310762d5796144a4ae95358211b
doc/bigdecimal/Bigdecimal/index.html
Module Bigdecimal
Source
A high-precision representation of decimal numbers as mantissa * 10^exponent
, where the mantissa is internally a Bigint.t
and the exponent is an int
.
include Sexplib0.Sexpable.S with type t := t
val t_of_sexp : Sexplib0.Sexp.t -> t
val sexp_of_t : t -> Sexplib0.Sexp.t
include Core.Bin_prot.Binable.S with type t := t
include Bin_prot.Binable.S_only_functions with type t := t
This function only needs implementation if t
exposed to be a polymorphic variant. Despite what the type reads, this does *not* produce a function after reading; instead it takes the constructor tag (int) before reading and reads the rest of the variant t
afterwards.
include Core.Comparable.S with type t := t
include Base.Comparable.S with type t := t
ascending
is identical to compare
. descending x y = ascending y x
. These are intended to be mnemonic when used like List.sort ~compare:ascending
and List.sort ~cmp:descending
, since they cause the list to be sorted in ascending or descending order, respectively.
clamp_exn t ~min ~max
returns t'
, the closest value to t
such that between t' ~low:min ~high:max
is true.
Raises if not (min <= max)
.
val comparator : (t, comparator_witness) Base__.Comparator.comparator
module Map :
Core.Map.S
with type Key.t = t
with type Key.comparator_witness = comparator_witness
module Set :
Core.Set.S
with type Elt.t = t
with type Elt.comparator_witness = comparator_witness
div ?decimals_precision a b
= a/b, to decimals_precision
decimals of precision, rounding to the nearest 10^(-decimals_precision).
decimals_precision
defaults to 15.
Computes the square root to decimals_precision
decimals of precision, rounding to the nearest 10^(-decimals_precision).
decimals_precision
defaults to 15.
Lossless conversion to Bignum.t
. Please note, however, that Bignum.to_string
may lose precision.
Converts to a string without using scientific notation (e.g., no e's show up in the middle, as in 1.3e12)
Like to_string_no_sn
but adds separators to group digits in the integral part into triplets, e.g. 1,234,567.890123
. sep
is comma by default.
Default rounding direction is `Nearest
.
Default rounding direction is `Nearest
.
Returns t
as an exact integer, if t
is integral and fits within int
; None otherwise.
Floating-point conversions
to_float
and of_float
round-trip when starting with a float.
to_float
is lossy, since not all decimals can be represented as floats. The result is the floating point number that is closest to the provided decimal.
Calculate the log in base 10. If it is not representable as an integer, return Option.None
Produces a decimal representation that, when converted back via to_float
, produces the original floating point number. It doesn't, however, pick the decimal that is exactly equal to the float, even though this exists.
Instead, it aims to minimize the length of the generated decimal, subject to the roundtrip property described above. See Float.to_string
for details on the semantics of the value chosen.
An error is returned in the case that the float is not representable as a decimal, e.g., NaN and infinity.
Produces a decimal representation that is exactly equal to the provided bignum, or an error if the bignum is not exactly representable as a decimal: e.g., infinity or 1/3
.