Module Decimal
Arbitrary precision real numbers
- author
- Christoph Sticksel
Pretty-printing and String Representation
val pp_print_decimal : Stdlib.Format.formatter -> t -> unit
Pretty-print a rational
val pp_print_decimal_as_float : Stdlib.Format.formatter -> t -> unit
Pretty-print a rational as an f64 (used by compilation to Rust)
val pp_print_decimal_as_lus_real : Stdlib.Format.formatter -> t -> unit
Pretty-print a rational as an f64 (used by contract generation)
val pp_print_decimal_approximation : Stdlib.Format.formatter -> t -> unit
Pretty-print a rational in scientific format with the error magnitude
val pp_print_decimal_sexpr : Stdlib.Format.formatter -> t -> unit
Pretty-print a rational as an S-expression
val pp_print_decimal_as_json : Stdlib.Format.formatter -> t -> unit
val string_of_decimal : t -> string
Return a string representation of a rational
val string_of_decimal_sexpr : t -> string
Return an S-expression string representation of a rational
Conversions
val of_int : int -> t
Convert an integer to a rational
val of_big_int : Big_int.big_int -> t
Convert an arbitrary large integer to a rational
val of_num : Num.num -> t
Convert an ocaml Num to a rational
val of_string : string -> t
Convert a string in floating-point notation
1.2E3
to rational number
val to_int : t -> int
Convert a rational number to a rational
Truncates the rational number to an integer and raises the exception
Failure "int_of_big_int"
if the numeral cannot be represented as an integer.
val to_big_int : t -> Big_int.big_int
Convert a rational number to an arbitrary large integer
val is_int : t -> bool
Return true if decimal coincides with an integer
val sign : t -> int
Returns 0 on zero, 1 for positives and -1 for negatives. Works also on infinites but fails on undefined.
val epsilon : int -> t
Returns the rational
2^p
with signed p.
val magnitude : t -> int
Returns a signed integer
n
such that2^(n-1) < |dec| < 2^n
or0
ifdec
is null.
Constants
val zero : t
The rational number zero
val one : t
The rational number one