---
name: "Num"
section: "3o"
platform: "linux"
package: "ocaml-nox"
version: "4.05.0-11"
release: "Debian 10 (Buster)"
platforms: ["linux"]
url: "https://new.carta.tech/Num"
---

# Num(3o)

Operation on arbitrary-precision numbers.

## NAME

Num - Operation on arbitrary-precision numbers.

## Module

Module   Num

## Documentation

Module **Num**\
  :  **sig end**

Operation on arbitrary-precision numbers.

Numbers (type  **num** ) are arbitrary-precision rational numbers, plus the special elements  **1/0** (infinity) and  **0/0** (undefined).

*type num* =\
  \| Int **of** **int**\
  \| Big\_int **of** **Big\_int.big\_int**\
  \| Ratio **of** **Ratio.ratio**

The type of numbers.

**===** **Arithmetic operations** **===**

*val (+/)* :  **num -\> num -\> num**

Same as  **Num.add\_num** .

*val add\_num* :  **num -\> num -\> num**

Addition

*val minus\_num* :  **num -\> num**

Unary negation.

*val (-/)* :  **num -\> num -\> num**

Same as  **Num.sub\_num** .

*val sub\_num* :  **num -\> num -\> num**

Subtraction

*val ( \*/ )* :  **num -\> num -\> num**

Same as  **Num.mult\_num** .

*val mult\_num* :  **num -\> num -\> num**

Multiplication

*val square\_num* :  **num -\> num**

Squaring

*val (//)* :  **num -\> num -\> num**

Same as  **Num.div\_num** .

*val div\_num* :  **num -\> num -\> num**

Division

*val quo\_num* :  **num -\> num -\> num**

Euclidean division: quotient.

*val mod\_num* :  **num -\> num -\> num**

Euclidean division: remainder.

*val ( \*\*/ )* :  **num -\> num -\> num**

Same as  **Num.power\_num** .

*val power\_num* :  **num -\> num -\> num**

Exponentiation

*val abs\_num* :  **num -\> num**

Absolute value.

*val succ\_num* :  **num -\> num**

**succ n** is  **n+1**

*val pred\_num* :  **num -\> num**

**pred n** is  **n-1**

*val incr\_num* :  **num Pervasives.ref -\> unit**

**incr r** is  **r:=!r+1** , where  **r** is a reference to a number.

*val decr\_num* :  **num Pervasives.ref -\> unit**

**decr r** is  **r:=!r-1** , where  **r** is a reference to a number.

*val is\_integer\_num* :  **num -\> bool**

Test if a number is an integer

**=== The four following functions approximate a number by an integer : ===**

*val integer\_num* :  **num -\> num**

**integer\_num n** returns the integer closest to  **n** . In case of ties, rounds towards zero.

*val floor\_num* :  **num -\> num**

**floor\_num n** returns the largest integer smaller or equal to  **n** .

*val round\_num* :  **num -\> num**

**round\_num n** returns the integer closest to  **n** . In case of ties, rounds off zero.

*val ceiling\_num* :  **num -\> num**

**ceiling\_num n** returns the smallest integer bigger or equal to  **n** .

*val sign\_num* :  **num -\> int**

Return  **-1** ,  **0** or  **1** according to the sign of the argument.

**===** **Comparisons between numbers** **===**

*val (=/)* :  **num -\> num -\> bool**

*val (\</)* :  **num -\> num -\> bool**

*val (\>/)* :  **num -\> num -\> bool**

*val (\<=/)* :  **num -\> num -\> bool**

*val (\>=/)* :  **num -\> num -\> bool**

*val (\<\>/)* :  **num -\> num -\> bool**

*val eq\_num* :  **num -\> num -\> bool**

*val lt\_num* :  **num -\> num -\> bool**

*val le\_num* :  **num -\> num -\> bool**

*val gt\_num* :  **num -\> num -\> bool**

*val ge\_num* :  **num -\> num -\> bool**

*val compare\_num* :  **num -\> num -\> int**

Return  **-1** ,  **0** or  **1** if the first argument is less than, equal to, or greater than the second argument.

*val max\_num* :  **num -\> num -\> num**

Return the greater of the two arguments.

*val min\_num* :  **num -\> num -\> num**

Return the smaller of the two arguments.

**===** **Coercions with strings** **===**

*val string\_of\_num* :  **num -\> string**

Convert a number to a string, using fractional notation.

*val approx\_num\_fix* :  **int -\> num -\> string**

See  **Num.approx\_num\_exp** .

*val approx\_num\_exp* :  **int -\> num -\> string**

Approximate a number by a decimal. The first argument is the required precision. The second argument is the number to approximate.  **Num.approx\_num\_fix** uses decimal notation; the first argument is the number of digits after the decimal point. **approx\_num\_exp** uses scientific (exponential) notation; the first argument is the number of digits in the mantissa.

*val num\_of\_string* :  **string -\> num**

Convert 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 option**

Convert a string to a number. Return  **None** if the given string is not a valid representation of an integer.

**Since** 4.05

**===** **Coercions between numerical types** **===**

*val int\_of\_num* :  **num -\> int**

*val int\_of\_num\_opt* :  **num -\> int option**

**Since** 4.05.0

*val num\_of\_int* :  **int -\> num**

*val nat\_of\_num* :  **num -\> Nat.nat**

*val nat\_of\_num\_opt* :  **num -\> Nat.nat option**

**Since** 4.05.0

*val num\_of\_nat* :  **Nat.nat -\> num**

*val num\_of\_big\_int* :  **Big\_int.big\_int -\> num**

*val big\_int\_of\_num* :  **num -\> Big\_int.big\_int**

*val big\_int\_of\_num\_opt* :  **num -\> Big\_int.big\_int option**

**Since** 4.05.0

*val ratio\_of\_num* :  **num -\> Ratio.ratio**

*val num\_of\_ratio* :  **Ratio.ratio -\> num**

*val float\_of\_num* :  **num -\> float**
