Module Std.Num
include Num
type num=|Int of int|Big_int of Big_int.big_int|Ratio of Ratio.ratioThe type of numbers.
Arithmetic operations
val (+/) : num -> num -> numSame as
Num.add_num.
val (-/) : num -> num -> numSame as
Num.sub_num.
val (*/) : num -> num -> numSame as
Num.mult_num.
val (//) : num -> num -> numSame as
Num.div_num.
val (**/) : num -> num -> numSame as
Num.power_num.
val incr_num : num Stdlib.ref -> unitincr risr:=!r+1, whereris a reference to a number.
val decr_num : num Stdlib.ref -> unitdecr risr:=!r-1, whereris a reference to a number.
val is_integer_num : num -> boolTest if a number is an integer
val integer_num : num -> numinteger_num nreturns the integer closest ton. In case of ties, rounds towards zero.
val round_num : num -> numround_num nreturns the integer closest ton. In case of ties, rounds off zero.
val sign_num : num -> intReturn
-1,0or1according to the sign of the argument.
Comparisons between numbers
val (=/) : num -> num -> boolval (</) : num -> num -> boolval (>/) : num -> num -> boolval (<=/) : num -> num -> boolval (>=/) : num -> num -> boolval (<>/) : num -> num -> boolval eq_num : num -> num -> boolval lt_num : num -> num -> boolval le_num : num -> num -> boolval gt_num : num -> num -> boolval ge_num : num -> num -> boolval compare_num : num -> num -> intReturn
-1,0or1if the first argument is less than, equal to, or greater than the second argument.
Coercions with strings
val string_of_num : num -> stringConvert a number to a string, using fractional notation.
val approx_num_fix : int -> num -> stringSee
Num.approx_num_exp.
val approx_num_exp : int -> num -> stringApproximate a number by a decimal. The first argument is the required precision. The second argument is the number to approximate.
Num.approx_num_fixuses decimal notation; the first argument is the number of digits after the decimal point.approx_num_expuses scientific (exponential) notation; the first argument is the number of digits in the mantissa.
val num_of_string : string -> numConvert a string to a number. Raise
Failure "num_of_string"if the given string is not a valid representation of an integer
val num_of_string_opt : string -> num optionConvert a string to a number. Return
Noneif the given string is not a valid representation of an integer.- since
- 4.05
Coercions between numerical types
val int_of_num : num -> intval int_of_num_opt : num -> int optionval num_of_int : int -> numval nat_of_num : num -> Nat.natval nat_of_num_opt : num -> Nat.nat optionval num_of_nat : Nat.nat -> numval num_of_big_int : Big_int.big_int -> numval big_int_of_num : num -> Big_int.big_intval big_int_of_num_opt : num -> Big_int.big_int optionval ratio_of_num : num -> Ratio.ratioval num_of_ratio : Ratio.ratio -> numval float_of_num : num -> float
val sexp_of_num : Num.num -> Sexplib.Sexp.tval num_of_sexp : Sexplib.Sexp.t -> Num.num