.TH "Num" 3o source: 2019-01-25 OCamldoc "OCaml library" .SH NAME Num \- Operation on arbitrary-precision numbers. .SH Module Module Num .SH Documentation .sp Module .BI "Num" : .B sig end .sp Operation on arbitrary\-precision numbers\&. .sp Numbers (type .B num ) are arbitrary\-precision rational numbers, plus the special elements .B 1/0 (infinity) and .B 0/0 (undefined)\&. .sp .sp .sp .I type num = | Int .B of .B int | Big_int .B of .B Big_int.big_int | Ratio .B of .B Ratio.ratio .sp The type of numbers\&. .sp .PP .B === .B Arithmetic operations .B === .PP .I val (+/) : .B num -> num -> num .sp Same as .B Num\&.add_num \&. .sp .I val add_num : .B num -> num -> num .sp Addition .sp .I val minus_num : .B num -> num .sp Unary negation\&. .sp .I val (-/) : .B num -> num -> num .sp Same as .B Num\&.sub_num \&. .sp .I val sub_num : .B num -> num -> num .sp Subtraction .sp .I val ( */ ) : .B num -> num -> num .sp Same as .B Num\&.mult_num \&. .sp .I val mult_num : .B num -> num -> num .sp Multiplication .sp .I val square_num : .B num -> num .sp Squaring .sp .I val (//) : .B num -> num -> num .sp Same as .B Num\&.div_num \&. .sp .I val div_num : .B num -> num -> num .sp Division .sp .I val quo_num : .B num -> num -> num .sp Euclidean division: quotient\&. .sp .I val mod_num : .B num -> num -> num .sp Euclidean division: remainder\&. .sp .I val ( **/ ) : .B num -> num -> num .sp Same as .B Num\&.power_num \&. .sp .I val power_num : .B num -> num -> num .sp Exponentiation .sp .I val abs_num : .B num -> num .sp Absolute value\&. .sp .I val succ_num : .B num -> num .sp .B succ n is .B n+1 .sp .I val pred_num : .B num -> num .sp .B pred n is .B n\-1 .sp .I val incr_num : .B num Pervasives.ref -> unit .sp .B incr r is .B r:=!r+1 , where .B r is a reference to a number\&. .sp .I val decr_num : .B num Pervasives.ref -> unit .sp .B decr r is .B r:=!r\-1 , where .B r is a reference to a number\&. .sp .I val is_integer_num : .B num -> bool .sp Test if a number is an integer .sp .PP .B === The four following functions approximate a number by an integer : === .PP .I val integer_num : .B num -> num .sp .B integer_num n returns the integer closest to .B n \&. In case of ties, rounds towards zero\&. .sp .I val floor_num : .B num -> num .sp .B floor_num n returns the largest integer smaller or equal to .B n \&. .sp .I val round_num : .B num -> num .sp .B round_num n returns the integer closest to .B n \&. In case of ties, rounds off zero\&. .sp .I val ceiling_num : .B num -> num .sp .B ceiling_num n returns the smallest integer bigger or equal to .B n \&. .sp .I val sign_num : .B num -> int .sp Return .B \-1 , .B 0 or .B 1 according to the sign of the argument\&. .sp .PP .B === .B Comparisons between numbers .B === .PP .I val (=/) : .B num -> num -> bool .sp .sp .I val ( num -> bool .sp .sp .I val (>/) : .B num -> num -> bool .sp .sp .I val (<=/) : .B num -> num -> bool .sp .sp .I val (>=/) : .B num -> num -> bool .sp .sp .I val (<>/) : .B num -> num -> bool .sp .sp .I val eq_num : .B num -> num -> bool .sp .sp .I val lt_num : .B num -> num -> bool .sp .sp .I val le_num : .B num -> num -> bool .sp .sp .I val gt_num : .B num -> num -> bool .sp .sp .I val ge_num : .B num -> num -> bool .sp .sp .I val compare_num : .B num -> num -> int .sp Return .B \-1 , .B 0 or .B 1 if the first argument is less than, equal to, or greater than the second argument\&. .sp .I val max_num : .B num -> num -> num .sp Return the greater of the two arguments\&. .sp .I val min_num : .B num -> num -> num .sp Return the smaller of the two arguments\&. .sp .PP .B === .B Coercions with strings .B === .PP .I val string_of_num : .B num -> string .sp Convert a number to a string, using fractional notation\&. .sp .I val approx_num_fix : .B int -> num -> string .sp See .B Num\&.approx_num_exp \&. .sp .I val approx_num_exp : .B int -> num -> string .sp Approximate a number by a decimal\&. The first argument is the required precision\&. The second argument is the number to approximate\&. .B Num\&.approx_num_fix uses decimal notation; the first argument is the number of digits after the decimal point\&. .B approx_num_exp uses scientific (exponential) notation; the first argument is the number of digits in the mantissa\&. .sp .I val num_of_string : .B string -> num .sp Convert a string to a number\&. Raise .B Failure "num_of_string" if the given string is not a valid representation of an integer .sp .I val num_of_string_opt : .B string -> num option .sp Convert a string to a number\&. Return .B None if the given string is not a valid representation of an integer\&. .sp .B "Since" 4.05 .sp .PP .B === .B Coercions between numerical types .B === .PP .I val int_of_num : .B num -> int .sp .sp .I val int_of_num_opt : .B num -> int option .sp .B "Since" 4.05.0 .sp .I val num_of_int : .B int -> num .sp .sp .I val nat_of_num : .B num -> Nat.nat .sp .sp .I val nat_of_num_opt : .B num -> Nat.nat option .sp .B "Since" 4.05.0 .sp .I val num_of_nat : .B Nat.nat -> num .sp .sp .I val num_of_big_int : .B Big_int.big_int -> num .sp .sp .I val big_int_of_num : .B num -> Big_int.big_int .sp .sp .I val big_int_of_num_opt : .B num -> Big_int.big_int option .sp .B "Since" 4.05.0 .sp .I val ratio_of_num : .B num -> Ratio.ratio .sp .sp .I val num_of_ratio : .B Ratio.ratio -> num .sp .sp .I val float_of_num : .B num -> float .sp .sp