Stdlib.Int(3) OCaml library Stdlib.Int(3)

# [NAME](#NAME)

Stdlib.Int - no description

# [Module](#Module)

Module Stdlib.Int

# [Documentation](#Documentation)

Module **Int**  
: **(module Stdlib\_\_Int)**

## [Integers](#Integers)

*type t* = **int**

The type for integer values.

*val zero* : **int**

**zero** is the integer **0** .

*val one* : **int**

**one** is the integer **1** .

*val minus\_one* : **int**

**minus\_one** is the integer **-1** .

*val neg* : **int -&gt; int**

**neg x** is **~-x** .

*val add* : **int -&gt; int -&gt; int**

**add x y** is the addition **x + y** .

*val sub* : **int -&gt; int -&gt; int**

**sub x y** is the subtraction **x - y** .

*val mul* : **int -&gt; int -&gt; int**

**mul x y** is the multiplication **x * y** .

*val div* : **int -&gt; int -&gt; int**

Rounding division. **div x y** is the real quotient **x / y** rounded towards zero to an integer. See **(/)** for details.

**Raises Division\_by\_zero** if the second argument is 0.

*val rem* : **int -&gt; int -&gt; int**

**rem x y** is the remainder of the rounding division **div x y** . We have **rem x y = x - div x y * y** . See **(mod)** for details.

**Raises Division\_by\_zero** if the second argument is 0.

*val fdiv* : **int -&gt; int -&gt; int**

Floor division. **fdiv x y** is the real quotient **x / y** rounded down to an integer. We have **fdiv x y &lt;= div x y &lt;= cdiv x y** and **cdiv x y - fdiv x y &lt;= 1** .

**Since** 5.5

**Raises Division\_by\_zero** if the second argument is 0.

*val cdiv* : **int -&gt; int -&gt; int**

Ceil division. **cdiv x y** is the real quotient **x / y** rounded up to an integer. We have **fdiv x y &lt;= div x y &lt;= cdiv x y** and **cdiv x y - fdiv x y &lt;= 1** .

**Since** 5.5

**Raises Division\_by\_zero** if the second argument is 0.

*val ediv* : **int -&gt; int -&gt; int**

Euclidean division. **ediv x y** is the real quotient **x / y** rounded down to an integer if **y &gt; 0** and rounded up to an integer if **y &lt; 0** . The remainder **erem x y = x - ediv x y * y** is always non-negative. Moreover, **ediv x (-y)** = **- ediv x y** .

**Since** 5.5

**Raises Division\_by\_zero** if the second argument is 0.

*val erem* : **int -&gt; int -&gt; int**

Euclidean remainder. If **y** is not zero, we have **x = ediv x y * y + erem x y** and **0 &lt;= erem x y &lt;= abs y - 1** . The result of **erem x y** is always non-negative, unlike the result of **rem x y** , which has the sign of **x** .

**Since** 5.5

**Raises Division\_by\_zero** if the second argument is 0.

*val succ* : **int -&gt; int**

**succ x** is **add x 1** .

*val pred* : **int -&gt; int**

**pred x** is **sub x 1** .

*val abs* : **int -&gt; int**

**abs x** is the absolute value of **x** . That is **x** if **x** is positive and **neg x** if **x** is negative. Warning. This may be negative if the argument is **Int.min\_int** .

*val max\_int* : **int**

**max\_int** is the greatest representable integer, **2** ^ **Sys.int\_size - 1** **-1** .

*val min\_int* : **int**

**min\_int** is the smallest representable integer, **-2** ^ **Sys.int\_size - 1** .

*val logand* : **int -&gt; int -&gt; int**

**logand x y** is the bitwise logical and of **x** and **y** .

*val logor* : **int -&gt; int -&gt; int**

**logor x y** is the bitwise logical or of **x** and **y** .

*val logxor* : **int -&gt; int -&gt; int**

**logxor x y** is the bitwise logical exclusive or of **x** and **y** .

*val lognot* : **int -&gt; int**

**lognot x** is the bitwise logical negation of **x** .

*val shift\_left* : **int -&gt; int -&gt; int**

**shift\_left x n** shifts **x** to the left by **n** bits. The result is unspecified if **n &lt; 0** or **n &gt;** **Sys.int\_size** .

*val shift\_right* : **int -&gt; int -&gt; int**

**shift\_right x n** shifts **x** to the right by **n** bits. This is an arithmetic shift: the sign bit of **x** is replicated and inserted in the vacated bits. The result is unspecified if **n &lt; 0** or **n &gt;** **Sys.int\_size** .

*val shift\_right\_logical* : **int -&gt; int -&gt; int**

**shift\_right\_logical x n** shifts **x** to the right by **n** bits. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of **x** . The result is unspecified if **n &lt; 0** or **n &gt;** **Sys.int\_size** .

## [Predicates and comparisons](#Predicates_and_comparisons)

*val equal* : **int -&gt; int -&gt; bool**

**equal x y** is **true** if and only if **x = y** .

*val compare* : **int -&gt; int -&gt; int**

**compare x y** is **compare** **x y** but more efficient.

*val min* : **int -&gt; int -&gt; int**

Return the smaller of the two arguments.

**Since** 4.13

*val max* : **int -&gt; int -&gt; int**

Return the greater of the two arguments.

**Since** 4.13

## [Bit counting](#Bit_counting)

*val popcount* : **t -&gt; int**

Population count, also known as Hamming weight. **popcount n** is the number of 1 bits in the binary representation of **n** . Negative **n** are represented in two's complement.

**Since** 5.5

*val unsigned\_bitsize* : **t -&gt; int**

**unsigned\_bitsize n** is the minimal number of bits needed to represent **n** as an unsigned binary number. It is the smallest integer **i** between 0 and **Sys.int\_size** inclusive such that **0 &lt;= n &lt; 2{^i}** (unsigned).

**Since** 5.5

*val signed\_bitsize* : **t -&gt; int**

**signed\_bitsize n** is the minimal number of bits needed to represent **n** as a signed, two's complement binary number. It is the smallest integer **i** between 1 and **Sys.int\_size** inclusive such that **-2{^i-1} &lt;= n &lt; 2{^i-1}** (signed).

**Since** 5.5

*val leading\_zeros* : **t -&gt; int**

**leading\_zeros n** is the number of leading (most significant) 0 bits in the binary representation of **n** . It is an integer between 0 and **Sys.int\_size** inclusive. If **n** is negative, **leading\_zeros n = 0** since the most significant bit of **n** is 1. **leading\_zeros n = {!Sys.int\_size}** if and only if **n = zero** . Note that **leading\_zeros n + unsigned\_bitsize n = {!Sys.int\_size}** .

**Since** 5.5

*val leading\_sign\_bits* : **t -&gt; int**

**leading\_sign\_bits n** is the number of leading (most significant) sign bits in the binary representation of **n** , excluding the sign bit itself. It is an integer between 0 and **{!Sys.int\_size} - 1** inclusive. For positive **n** , it is the number of leading zero bits minus one. For negative **n** , it is the number of leading one bits minus one. Note that **leading\_sign\_bits n + signed\_bitsize n = {!Sys.int\_size}** .

**Since** 5.5

*val trailing\_zeros* : **t -&gt; int**

**trailing\_zeros n** is the number of trailing (least significant) 0 bits in the binary representation of **n** . It is an integer between 0 and **Sys.int\_size** inclusive. It is the largest integer **i &lt;= {!Sys.int\_size}** such that **2{^i}** divides **n** evenly. For example, **trailing\_zeros n = 0** if and only if **n** is odd, and **trailing\_zeros n = {!Sys.int\_size}** if and only if **n = zero** .

**Since** 5.5

## [Converting](#Converting)

*val to\_float* : **int -&gt; float**

**to\_float x** is **x** as a floating point number.

*val of\_float* : **float -&gt; int**

**of\_float x** truncates **x** to an integer. The result is unspecified if the argument is **nan** or falls outside the range of representable integers.

*val to\_string* : **int -&gt; string**

**to\_string x** is the written representation of **x** in decimal.

*val seeded\_hash* : **int -&gt; int -&gt; int**

A seeded hash function for ints, with the same output value as **Hashtbl.seeded\_hash** . This function allows this module to be passed as argument to the functor **Hashtbl.MakeSeeded** .

**Since** 5.1

*val hash* : **int -&gt; int**

An unseeded hash function for ints, with the same output value as **Hashtbl.hash** . This function allows this module to be passed as argument to the functor **Hashtbl.Make** .

**Since** 5.1

2026-10-01 OCamldoc

---

Document: Stdlib.Int(3o) from ocaml 5.5.1-r1 (Chainguard OS)
Source: https://github.com/ocaml/ocaml
