Module Decimal
Arbitrary precision real numbers
- author
- Christoph Sticksel
Pretty-printing and String Representation
val pp_print_decimal : Stdlib.Format.formatter -> t -> unitPretty-print a rational
val pp_print_decimal_as_float : Stdlib.Format.formatter -> t -> unitPretty-print a rational as an f64 (used by compilation to Rust)
val pp_print_decimal_as_lus_real : Stdlib.Format.formatter -> t -> unitPretty-print a rational as an f64 (used by contract generation)
val pp_print_decimal_approximation : Stdlib.Format.formatter -> t -> unitPretty-print a rational in scientific format with the error magnitude
val pp_print_decimal_sexpr : Stdlib.Format.formatter -> t -> unitPretty-print a rational as an S-expression
val pp_print_decimal_as_json : Stdlib.Format.formatter -> t -> unitval string_of_decimal : t -> stringReturn a string representation of a rational
val string_of_decimal_sexpr : t -> stringReturn an S-expression string representation of a rational
Conversions
val of_int : int -> tConvert an integer to a rational
val of_big_int : Big_int.big_int -> tConvert an arbitrary large integer to a rational
val of_num : Num.num -> tConvert an ocaml Num to a rational
val of_string : string -> tConvert a string in floating-point notation
1.2E3to rational number
val to_int : t -> intConvert 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_intConvert a rational number to an arbitrary large integer
val is_int : t -> boolReturn true if decimal coincides with an integer
val sign : t -> intReturns 0 on zero, 1 for positives and -1 for negatives. Works also on infinites but fails on undefined.
val epsilon : int -> tReturns the rational
2^pwith signed p.
val magnitude : t -> intReturns a signed integer
nsuch that2^(n-1) < |dec| < 2^nor0ifdecis null.
Constants
val zero : tThe rational number zero
val one : tThe rational number one