.TH "Int32" 3 2026-06-22 OCamldoc "OCaml library" .SH NAME Int32 \- 32-bit integers. .SH Module Module Int32 .SH Documentation .sp Module .BI "Int32" : .B sig end .sp 32\-bit integers\&. .sp This module provides operations on the type .ft B int32 .ft R of signed 32\-bit integers\&. Unlike the built\-in .ft B int .ft R type, the type .ft B int32 .ft R is guaranteed to be exactly 32\-bit wide on all platforms\&. All arithmetic operations over .ft B int32 .ft R are taken modulo 2^32\&. .sp Performance notice: values of type .ft B int32 .ft R occupy more memory space than values of type .ft B int .ft R , and arithmetic operations on .ft B int32 .ft R are generally slower than those on .ft B int .ft R \&. Use .ft B int32 .ft R only when the application requires exact 32\-bit arithmetic\&. .sp Literals for 32\-bit integers are suffixed by l: .EX .ft B .br \& let zero: int32 = 0l .br \& let one: int32 = 1l .br \& let m_one: int32 = \-1l .br \& .ft R .EE .sp .sp .sp .I val zero : .B int32 .sp The 32\-bit integer 0\&. .sp .I val one : .B int32 .sp The 32\-bit integer 1\&. .sp .I val minus_one : .B int32 .sp The 32\-bit integer \-1\&. .sp .I val neg : .B int32 -> int32 .sp Unary negation\&. .sp .I val add : .B int32 -> int32 -> int32 .sp Addition\&. .sp .I val sub : .B int32 -> int32 -> int32 .sp Subtraction\&. .sp .I val mul : .B int32 -> int32 -> int32 .sp Multiplication\&. .sp .I val div : .B int32 -> int32 -> int32 .sp Integer division\&. This division rounds the real quotient of its arguments towards zero, as specified for .ft B (/) .ft R \&. .sp .B "Raises Division_by_zero" if the second argument is zero\&. .sp .I val unsigned_div : .B int32 -> int32 -> int32 .sp Same as .ft B Int32\&.div .ft R , except that arguments and result are interpreted as unsigned 32\-bit integers\&. .sp .B "Since" 4.08 .sp .I val rem : .B int32 -> int32 -> int32 .sp Integer remainder\&. If .ft B y .ft R is not zero, the result of .ft B Int32\&.rem x y .ft R satisfies the following property: .ft B x = Int32\&.add (Int32\&.mul (Int32\&.div x y) y) (Int32\&.rem x y) .ft R \&. If .ft B y = 0 .ft R , .ft B Int32\&.rem x y .ft R raises .ft B Division_by_zero .ft R \&. .sp .I val unsigned_rem : .B int32 -> int32 -> int32 .sp Same as .ft B Int32\&.rem .ft R , except that arguments and result are interpreted as unsigned 32\-bit integers\&. .sp .B "Since" 4.08 .sp .I val fdiv : .B int32 -> int32 -> int32 .sp Floor division\&. .ft B fdiv x y .ft R is the real quotient .ft B x / y .ft R rounded down to an integer\&. We have .ft B fdiv x y <= div x y <= cdiv x y .ft R and .ft B cdiv x y \- fdiv x y <= 1 .ft R \&. .sp .B "Since" 5.5 .sp .B "Raises Division_by_zero" if the second argument is 0\&. .sp .I val cdiv : .B int32 -> int32 -> int32 .sp Ceil division\&. .ft B cdiv x y .ft R is the real quotient .ft B x / y .ft R rounded up to an integer\&. We have .ft B fdiv x y <= div x y <= cdiv x y .ft R and .ft B cdiv x y \- fdiv x y <= 1 .ft R \&. .sp .B "Since" 5.5 .sp .B "Raises Division_by_zero" if the second argument is 0\&. .sp .I val ediv : .B int32 -> int32 -> int32 .sp Euclidean division\&. .ft B ediv x y .ft R is the real quotient .ft B x / y .ft R rounded down to an integer if .ft B y > 0 .ft R and rounded up to an integer if .ft B y < 0 .ft R \&. The remainder .ft B erem x y = x \- ediv x y * y .ft R is always non\-negative\&. Moreover, .ft B ediv x (\-y) .ft R = .ft B \- ediv x y .ft R \&. .sp .B "Since" 5.5 .sp .B "Raises Division_by_zero" if the second argument is 0\&. .sp .I val erem : .B int32 -> int32 -> int32 .sp Euclidean remainder\&. If .ft B y .ft R is not zero, we have .ft B x = ediv x y * y + erem x y .ft R and .ft B 0 <= erem x y <= abs y \- 1 .ft R \&. The result of .ft B erem x y .ft R is always non\-negative, unlike the result of .ft B rem x y .ft R , which has the sign of .ft B x .ft R \&. .sp .B "Since" 5.5 .sp .B "Raises Division_by_zero" if the second argument is 0\&. .sp .I val succ : .B int32 -> int32 .sp Successor\&. .ft B Int32\&.succ x .ft R is .ft B Int32\&.add x Int32\&.one .ft R \&. .sp .I val pred : .B int32 -> int32 .sp Predecessor\&. .ft B Int32\&.pred x .ft R is .ft B Int32\&.sub x Int32\&.one .ft R \&. .sp .I val abs : .B int32 -> int32 .sp .ft B abs x .ft R is the absolute value of .ft B x .ft R \&. On .ft B min_int .ft R this is .ft B min_int .ft R itself and thus remains negative\&. .sp .I val max_int : .B int32 .sp The greatest representable 32\-bit integer, 2^31 \- 1\&. .sp .I val min_int : .B int32 .sp The smallest representable 32\-bit integer, \-2^31\&. .sp .I val logand : .B int32 -> int32 -> int32 .sp Bitwise logical and\&. .sp .I val logor : .B int32 -> int32 -> int32 .sp Bitwise logical or\&. .sp .I val logxor : .B int32 -> int32 -> int32 .sp Bitwise logical exclusive or\&. .sp .I val lognot : .B int32 -> int32 .sp Bitwise logical negation\&. .sp .I val shift_left : .B int32 -> int -> int32 .sp .ft B Int32\&.shift_left x y .ft R shifts .ft B x .ft R to the left by .ft B y .ft R bits\&. The result is unspecified if .ft B y < 0 .ft R or .ft B y >= 32 .ft R \&. .sp .I val shift_right : .B int32 -> int -> int32 .sp .ft B Int32\&.shift_right x y .ft R shifts .ft B x .ft R to the right by .ft B y .ft R bits\&. This is an arithmetic shift: the sign bit of .ft B x .ft R is replicated and inserted in the vacated bits\&. The result is unspecified if .ft B y < 0 .ft R or .ft B y >= 32 .ft R \&. .sp .I val shift_right_logical : .B int32 -> int -> int32 .sp .ft B Int32\&.shift_right_logical x y .ft R shifts .ft B x .ft R to the right by .ft B y .ft R bits\&. This is a logical shift: zeroes are inserted in the vacated bits regardless of the sign of .ft B x .ft R \&. The result is unspecified if .ft B y < 0 .ft R or .ft B y >= 32 .ft R \&. .sp .I val of_int : .B int -> int32 .sp Convert the given integer (type .ft B int .ft R ) to a 32\-bit integer (type .ft B int32 .ft R )\&. On 64\-bit platforms, the argument is taken modulo 2^32\&. .sp .I val to_int : .B int32 -> int .sp Convert the given 32\-bit integer (type .ft B int32 .ft R ) to an integer (type .ft B int .ft R )\&. On 32\-bit platforms, the 32\-bit integer is taken modulo 2^31, i\&.e\&. the high\-order bit is lost during the conversion\&. On 64\-bit platforms, the conversion is exact\&. .sp .I val unsigned_to_int : .B int32 -> int option .sp Same as .ft B Int32\&.to_int .ft R , but interprets the argument as an unsigned integer\&. Returns .ft B None .ft R if the unsigned value of the argument cannot fit into an .ft B int .ft R \&. .sp .B "Since" 4.08 .sp .I val of_float : .B float -> int32 .sp Convert the given floating\-point number to a 32\-bit integer, discarding the fractional part (truncate towards 0)\&. If the truncated floating\-point number is outside the range [ .ft B Int32\&.min_int .ft R , .ft B Int32\&.max_int .ft R ], no exception is raised, and an unspecified, platform\-dependent integer is returned\&. .sp .I val to_float : .B int32 -> float .sp Convert the given 32\-bit integer to a floating\-point number\&. .sp .I val of_string : .B string -> int32 .sp Convert the given string to a 32\-bit integer\&. The string is read in decimal (by default, or if the string begins with .ft B 0u .ft R ) or in hexadecimal, octal or binary if the string begins with .ft B 0x .ft R , .ft B 0o .ft R or .ft B 0b .ft R respectively\&. .sp The .ft B 0u .ft R prefix reads the input as an unsigned integer in the range .ft B [0, 2*Int32\&.max_int+1] .ft R \&. If the input exceeds .ft B Int32\&.max_int .ft R it is converted to the signed integer .ft B Int32\&.min_int + input \- Int32\&.max_int \- 1 .ft R \&. .sp The .ft B _ .ft R (underscore) character can appear anywhere in the string and is ignored\&. .sp .B "Raises Failure" if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in type .ft B int32 .ft R \&. .sp .I val of_string_opt : .B string -> int32 option .sp Same as .ft B of_string .ft R , but return .ft B None .ft R instead of raising\&. .sp .B "Since" 4.05 .sp .I val to_string : .B int32 -> string .sp Return the string representation of its argument, in signed decimal\&. .sp .I val bits_of_float : .B float -> int32 .sp Return the internal representation of the given float according to the IEEE 754 floating\-point \&'single format\&' bit layout\&. Bit 31 of the result represents the sign of the float; bits 30 to 23 represent the (biased) exponent; bits 22 to 0 represent the mantissa\&. .sp .I val float_of_bits : .B int32 -> float .sp Return the floating\-point number whose internal representation, according to the IEEE 754 floating\-point \&'single format\&' bit layout, is the given .ft B int32 .ft R \&. .sp .I type t = .B int32 .sp An alias for the type of 32\-bit integers\&. .sp .I val compare : .B t -> t -> int .sp The comparison function for 32\-bit integers, with the same specification as .ft B compare .ft R \&. Along with the type .ft B t .ft R , this function .ft B compare .ft R allows the module .ft B Int32 .ft R to be passed as argument to the functors .ft B Set\&.Make .ft R and .ft B Map\&.Make .ft R \&. .sp .I val unsigned_compare : .B t -> t -> int .sp Same as .ft B Int32\&.compare .ft R , except that arguments are interpreted as unsigned 32\-bit integers\&. .sp .B "Since" 4.08 .sp .I val equal : .B t -> t -> bool .sp The equal function for int32s\&. .sp .B "Since" 4.03 .sp .I val min : .B t -> t -> t .sp Return the smaller of the two arguments\&. .sp .B "Since" 4.13 .sp .I val max : .B t -> t -> t .sp Return the greater of the two arguments\&. .sp .B "Since" 4.13 .sp .I val popcount : .B t -> int .sp Population count, also known as Hamming weight\&. .ft B popcount n .ft R is the number of 1 bits in the binary representation of .ft B n .ft R \&. Negative .ft B n .ft R are represented in two\&'s complement\&. .sp .B "Since" 5.5 .sp .I val unsigned_bitsize : .B t -> int .sp .ft B unsigned_bitsize n .ft R is the minimal number of bits needed to represent .ft B n .ft R as an unsigned binary number\&. It is the smallest integer .ft B i .ft R between 0 and 32 inclusive such that .ft B 0 <= n < 2{^i} .ft R (unsigned)\&. .sp .B "Since" 5.5 .sp .I val signed_bitsize : .B t -> int .sp .ft B signed_bitsize n .ft R is the minimal number of bits needed to represent .ft B n .ft R as a signed, two\&'s complement binary number\&. It is the smallest integer .ft B i .ft R between 1 and 32 inclusive such that .ft B \-2{^i\-1} <= n < 2{^i\-1} .ft R (signed)\&. .sp .B "Since" 5.5 .sp .I val leading_zeros : .B t -> int .sp .ft B leading_zeros n .ft R is the number of leading (most significant) 0 bits in the binary representation of .ft B n .ft R \&. It is an integer between 0 and 32 inclusive\&. If .ft B n .ft R is negative, .ft B leading_zeros n = 0 .ft R since the most significant bit of .ft B n .ft R is 1\&. .ft B leading_zeros n = 32 .ft R if and only if .ft B n = zero .ft R \&. Note that .ft B leading_zeros n + unsigned_bitsize n = 32 .ft R \&. .sp .B "Since" 5.5 .sp .I val leading_sign_bits : .B t -> int .sp .ft B leading_sign_bits n .ft R is the number of leading (most significant) sign bits in the binary representation of .ft B n .ft R , excluding the sign bit itself\&. It is an integer between 0 and 31 inclusive\&. For positive .ft B n .ft R , it is the number of leading zero bits minus one\&. For negative .ft B n .ft R , it is the number of leading one bits minus one\&. Note that .ft B leading_sign_bits n + signed_bitsize n = 32 .ft R \&. .sp .B "Since" 5.5 .sp .I val trailing_zeros : .B t -> int .sp .ft B trailing_zeros n .ft R is the number of trailing (least significant) 0 bits in the binary representation of .ft B n .ft R \&. It is an integer between 0 and 32 inclusive\&. It is the largest integer .ft B i <= 32 .ft R such that .ft B 2{^i} .ft R divides .ft B n .ft R evenly\&. For example, .ft B trailing_zeros n = 0 .ft R if and only if .ft B n .ft R is odd, and .ft B trailing_zeros n = 32 .ft R if and only if .ft B n = zero .ft R \&. .sp .B "Since" 5.5 .sp .I val seeded_hash : .B int -> t -> int .sp A seeded hash function for 32\-bit ints, with the same output value as .ft B Hashtbl\&.seeded_hash .ft R \&. This function allows this module to be passed as argument to the functor .ft B Hashtbl\&.MakeSeeded .ft R \&. .sp .B "Since" 5.1 .sp .I val hash : .B t -> int .sp An unseeded hash function for 32\-bit ints, with the same output value as .ft B Hashtbl\&.hash .ft R \&. This function allows this module to be passed as argument to the functor .ft B Hashtbl\&.Make .ft R \&. .sp .B "Since" 5.1 .sp