Module Number

module Number: sig .. end

General functions for representations of numeric values


exception InvalidConstantLiteral of int * string
type int_value = BigInt.t 
type int_literal_kind = 
| ILitUnk
| ILitDec
| ILitHex
| ILitOct
| ILitBin
type int_constant = {
   il_kind : int_literal_kind;
   il_int : int_value;
}
type real_value = private {
   rv_sig : BigInt.t;
   rv_pow2 : BigInt.t;
   rv_pow5 : BigInt.t;
}
type real_literal_kind = 
| RLitUnk
| RLitDec of int
| RLitHex of int
type real_constant = {
   rl_kind : real_literal_kind;
   rl_real : real_value;
}
val neg_int : int_constant -> int_constant
val abs_int : int_constant -> int_constant
val neg_real : real_constant -> real_constant
val abs_real : real_constant -> real_constant
val compare_real : ?structural:bool -> real_value -> real_value -> int

Compare two real values. By default, the comparison is structural, that is, two ordered values might compare differently.

val int_literal : int_literal_kind -> neg:bool -> string -> int_constant
val real_literal : radix:int ->
neg:bool ->
int:string -> frac:string -> exp:string option -> real_constant

real_literal ~radix ~neg ~int ~frac ~exp builds the real value given by the mantissa int.frac and exponent exp. The radix must be either 10 or 16. If radix is 16, then int and frac are interpreted in hexadecimal (but not exp which is always in decimal) and the base of the exponent is 2 instead of 10. The resulting number is negative when neg is true.

Examples:

val real_value : ?pow2:BigInt.t -> ?pow5:BigInt.t -> BigInt.t -> real_value

real_value ~pow2 ~pow5 n builds the value n * 2 ^ pow2 * 5 ^ pow5.

Pretty-printing with conversion

type default_format = Stdlib.Format.formatter -> string -> unit 
type integer_format = Stdlib.Format.formatter -> BigInt.t -> unit 
type real_format = Stdlib.Format.formatter -> string -> string -> string option -> unit 
type frac_real_format = (Stdlib.Format.formatter -> string -> unit) *
(Stdlib.Format.formatter -> string -> string -> unit)
type delayed_format = Stdlib.Format.formatter -> (Stdlib.Format.formatter -> unit) -> unit 
type number_support = {
   long_int_support : [ `Custom of default_format | `Default ];
   negative_int_support : [ `Custom of delayed_format | `Default ];
   dec_int_support : [ `Custom of integer_format
| `Default
| `Unsupported of default_format ]
;
   hex_int_support : [ `Custom of integer_format | `Default | `Unsupported ];
   oct_int_support : [ `Custom of integer_format | `Default | `Unsupported ];
   bin_int_support : [ `Custom of integer_format | `Default | `Unsupported ];
   negative_real_support : [ `Custom of delayed_format | `Default ];
   dec_real_support : [ `Custom of real_format | `Default | `Unsupported ];
   hex_real_support : [ `Custom of real_format | `Default | `Unsupported ];
   frac_real_support : [ `Custom of frac_real_format | `Unsupported of default_format
]
;
}
val full_support : number_support
val print_int_constant : number_support ->
Stdlib.Format.formatter -> int_constant -> unit
val print_real_constant : number_support ->
Stdlib.Format.formatter -> real_constant -> unit
val print_in_base : int -> int option -> Stdlib.Format.formatter -> BigInt.t -> unit

print_in_base radix digits fmt i prints the value of non-negative i in base radix. If digits is not None, it adds leading 0s to have digits characters.

Range checking

val to_small_integer : int_constant -> int
type int_range = {
   ir_lower : BigInt.t;
   ir_upper : BigInt.t;
}
val create_range : BigInt.t -> BigInt.t -> int_range
exception OutOfRange of int_constant
val check_range : int_constant -> int_range -> unit

check_range c ir checks that c is in the range described by ir.

val int_range_equal : int_range -> int_range -> bool

Float checking

type float_format = {
   fp_exponent_digits : int;
   fp_significand_digits : int;
}
exception NonRepresentableFloat of real_constant
val compute_float : real_constant -> float_format -> bool * BigInt.t * BigInt.t

compute_float c fp checks that c is a float literal representable in the format fp.

val check_float : real_constant -> float_format -> unit

check_float c fp is the same as compute_float c fp but does not return any value.

val float_format_equal : float_format -> float_format -> bool