Int64(3)

๐Ÿ’– NAME ๐Ÿ’–

Int64 โ€” 64-bit integers. that's the whole vibe bestie, sixty-four whole bits of integer โœจ (she lives in the OCaml library, hi ๐Ÿซถ)

๐Ÿฆ‹ MODULE ๐Ÿฆ‹

Module Int64

โœจ DOCUMENTATION โœจ

Module Int64 : sig end

okay so picture this: 64-bit integers. ๐Ÿ’…

This module gives you all the operations on the type int64, which is signed 64-bit integers. And here's the part that genuinely slays โ€” unlike the built-in int type, int64 is guaranteed to be exactly 64-bit wide on every single platform. no cap. And every arithmetic operation over int64 is taken modulo 2^64.

โš ๏ธ performance notice, listen up: values of type int64 take up more memory space than values of type int, and arithmetic operations on int64 are generally slower than the ones on int. so only use int64 when your application actually requires exact 64-bit arithmetic, okay? don't be out here choosing int64 for the aesthetic. ๐Ÿ™ˆ

Literals for 64-bit integers get an L suffix, like this:

let zero: int64 = 0L
let one: int64 = 1L
let m_one: int64 = -1L

๐ŸŽ€ the constants & the arithmetic ๐ŸŽ€

  • val zero : int64 โ€” the 64-bit integer 0. the origin story โœจ
  • val one : int64 โ€” the 64-bit integer 1. iconic, no notes.
  • val minus_one : int64 โ€” the 64-bit integer -1. yes she's real and yes she's negative.
  • val neg : int64 -> int64 โ€” unary negation. flip the sign, that's it.
  • val add : int64 -> int64 -> int64 โ€” addition. math but make it 64-bit ๐Ÿ’–
  • val sub : int64 -> int64 -> int64 โ€” subtraction. taking things away, emotionally.
  • val mul : int64 -> int64 -> int64 โ€” multiplication. the way it multiplies. obsessed.
  • val div : int64 -> int64 -> int64 โ€” integer division.
๐Ÿซถ raises Division_by_zero if the second argument is zero. also heads up: this division rounds the real quotient of its arguments towards zero, as specified for (/).
  • val unsigned_div : int64 -> int64 -> int64 โ€” same as Int64.div, except that the arguments and the result are interpreted as unsigned 64-bit integers.

Since 4.08

  • val rem : int64 -> int64 -> int64 โ€” integer remainder. if y is not zero, then the result of Int64.rem x y satisfies this property, memorize it for the exam:

x = Int64.add (Int64.mul (Int64.div x y) y) (Int64.rem x y)

if y = 0, Int64.rem x y raises Division_by_zero.

  • val unsigned_rem : int64 -> int64 -> int64 โ€” same as Int64.rem, except that the arguments and the result are interpreted as unsigned 64-bit integers.

Since 4.08

  • val fdiv : int64 -> int64 -> int64 โ€” floor division. fdiv x y is the real quotient x / y rounded down to an integer. we have fdiv x y <= div x y <= cdiv x y and cdiv x y - fdiv x y <= 1. ๐Ÿฆ‹

Since 5.5

raises Division_by_zero if the second argument is 0.
  • val cdiv : int64 -> int64 -> int64 โ€” ceil division. cdiv x y is the real quotient x / y rounded up to an integer. we have fdiv x y <= div x y <= cdiv x y and cdiv x y - fdiv x y <= 1. ๐ŸŒธ

Since 5.5

raises Division_by_zero if the second argument is 0.
  • val ediv : int64 -> int64 -> int64 โ€” Euclidean division. ediv x y is the real quotient x / y rounded down to an integer if y > 0 and rounded up to an integer if y < 0. the remainder erem x y = x - ediv x y * y is always non-negative. and moreover (fancy word, i know), ediv x (-y) = - ediv x y. ๐Ÿ’…

Since 5.5

raises Division_by_zero if the second argument is 0.
  • val erem : int64 -> int64 -> int64 โ€” Euclidean remainder. if y is not zero, we have x = ediv x y * y + erem x y and 0 <= erem x y <= 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. that's the whole plot twist right there ๐Ÿ˜ญ

Since 5.5

raises Division_by_zero if the second argument is 0.
  • val succ : int64 -> int64 โ€” successor. Int64.succ x is Int64.add x Int64.one. she's giving next.
  • val pred : int64 -> int64 โ€” predecessor. Int64.pred x is Int64.sub x Int64.one. she's giving previous. main character energy both ways ๐Ÿ”ฅ
  • val abs : int64 -> int64 โ€” abs x is the absolute value of x. but bestie, listen: on min_int this is min_int itself and thus remains negative. the absolute value that isn't absolute. ๐Ÿ’€
  • val max_int : int64 โ€” the greatest representable 64-bit integer, 2^63 - 1. the ceiling, literally ๐Ÿ‘‘
  • val min_int : int64 โ€” the smallest representable 64-bit integer, -2^63. the floor. we respect her.

๐Ÿงš the bitwise girlies ๐Ÿงš

  • val logand : int64 -> int64 -> int64 โ€” bitwise logical and.
  • val logor : int64 -> int64 -> int64 โ€” bitwise logical or.
  • val logxor : int64 -> int64 -> int64 โ€” bitwise logical exclusive or. the exclusive one, she doesn't do groups.
  • val lognot : int64 -> int64 โ€” bitwise logical negation.
  • val shift_left : int64 -> int -> int64 โ€” Int64.shift_left x y shifts x to the left by y bits.
๐Ÿšจ the result is unspecified if y < 0 or y >= 64. undefined-ish behavior is not a vibe, don't do it.
  • val shift_right : int64 -> int -> int64 โ€” Int64.shift_right x y shifts x to the right by y bits. this one's an arithmetic shift: the sign bit of x is replicated and inserted in the vacated bits.
๐Ÿšจ the result is unspecified if y < 0 or y >= 64.
  • val shift_right_logical : int64 -> int -> int64 โ€” Int64.shift_right_logical x y shifts x to the right by y bits. this one's a logical shift: zeroes are inserted in the vacated bits regardless of the sign of x.
๐Ÿšจ the result is unspecified if y < 0 or y >= 64.

๐ŸŒˆ conversions ๐ŸŒˆ

  • val of_int : int -> int64 โ€” convert the given integer (type int) to a 64-bit integer (type int64).
  • val to_int : int64 -> int โ€” convert the given 64-bit integer (type int64) to an integer (type int). on 64-bit platforms, the 64-bit integer is taken modulo 2^63, i.e. the high-order bit is lost during the conversion. on 32-bit platforms, the 64-bit integer is taken modulo 2^31, i.e. the top 33 bits are lost during the conversion. bits simply leaving the chat ๐Ÿ˜ญ
  • val unsigned_to_int : int64 -> int option โ€” same as Int64.to_int, but interprets the argument as an unsigned integer. returns None if the unsigned value of the argument cannot fit into an int.

Since 4.08

  • val of_float : float -> int64 โ€” convert the given floating-point number to a 64-bit integer, discarding the fractional part (truncate towards 0).
๐Ÿ’€ if the truncated floating-point number is outside the range [ Int64.min_int , Int64.max_int ], no exception is raised, and an unspecified, platform-dependent integer is returned. so like... good luck? i don't make the rules.
  • val to_float : int64 -> float โ€” convert the given 64-bit integer to a floating-point number.
  • val of_int32 : int32 -> int64 โ€” convert the given 32-bit integer (type int32) to a 64-bit integer (type int64). glow-up.
  • val to_int32 : int64 -> int32 โ€” convert the given 64-bit integer (type int64) to a 32-bit integer (type int32). the 64-bit integer is taken modulo 2^32, i.e. the top 32 bits are lost during the conversion. sorry to those bits specifically ๐Ÿ™ˆ
  • val of_nativeint : nativeint -> int64 โ€” convert the given native integer (type nativeint) to a 64-bit integer (type int64).
  • val to_nativeint : int64 -> nativeint โ€” convert the given 64-bit integer (type int64) to a native integer. on 32-bit platforms, the 64-bit integer is taken modulo 2^32. on 64-bit platforms, the conversion is exact. โœจ (the 64-bit platform girlies stay winning)

๐Ÿ“ strings ๐Ÿ“

  • val of_string : string -> int64 โ€” convert the given string to a 64-bit integer. the string is read in decimal (by default, or if the string begins with 0u) or in hexadecimal, octal or binary if the string begins with 0x, 0o or 0b respectively.

the 0u prefix reads the input as an unsigned integer in the range [0, 2*Int64.max_int+1]. if the input exceeds Int64.max_int it is converted to the signed integer Int64.min_int + input - Int64.max_int - 1.

the _ (underscore) character can appear anywhere in the string and is ignored. aesthetic underscores, we love to see it ๐Ÿ’…

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 int64.
  • val of_string_opt : string -> int64 option โ€” same as of_string, but returns None instead of raising. so much more chill of her honestly.

Since 4.05

  • val to_string : int64 -> string โ€” return the string representation of its argument, in decimal.

๐Ÿฆ‹ floats, but the bit-level tea ๐Ÿฆ‹

  • val bits_of_float : float -> int64 โ€” return the internal representation of the given float according to the IEEE 754 floating-point 'double format' bit layout. bit 63 of the result represents the sign of the float; bits 62 to 52 represent the (biased) exponent; bits 51 to 0 represent the mantissa. look at all those little bits living their lives ๐Ÿ’–
  • val float_of_bits : int64 -> float โ€” return the floating-point number whose internal representation, according to the IEEE 754 floating-point 'double format' bit layout, is the given int64.

๐Ÿ‘‘ the type & the comparisons ๐Ÿ‘‘

  • type t = int64 โ€” an alias for the type of 64-bit integers. same girl, different name tag.
  • val compare : t -> t -> int โ€” the comparison function for 64-bit integers, with the same specification as compare. along with the type t, this function compare allows the module Int64 to be passed as argument to the functors Set.Make and Map.Make. she's plug-and-play, we stan ๐Ÿซถ
  • val unsigned_compare : t -> t -> int โ€” same as Int64.compare, except that the arguments are interpreted as unsigned 64-bit integers.

Since 4.08

  • val equal : t -> t -> bool โ€” the equal function for int64s.

Since 4.03

  • val min : t -> t -> t โ€” return the smaller of the two arguments.

Since 4.13

  • val max : t -> t -> t โ€” return the greater of the two arguments.

Since 4.13


โญ counting bits & hashing โญ

  • val popcount : t -> 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. literally just counting the ones, she's so real for that ๐Ÿ”ฅ

Since 5.5

  • val unsigned_bitsize : t -> int โ€” unsigned_bitsize n is the minimal number of bits needed to represent n as an unsigned binary number. it's the smallest integer i between 0 and 64 inclusive such that 0 <= n < 2{^i} (unsigned).

Since 5.5

  • val signed_bitsize : t -> int โ€” signed_bitsize n is the minimal number of bits needed to represent n as a signed, two's complement binary number. it's the smallest integer i between 1 and 64 inclusive such that -2{^i-1} <= n < 2{^i-1} (signed).

Since 5.5

  • val leading_zeros : t -> int โ€” leading_zeros n is the number of leading (most significant) 0 bits in the binary representation of n. it's an integer between 0 and 64 inclusive. if n is negative, leading_zeros n = 0 since the most significant bit of n is 1. leading_zeros n = 64 if and only if n = zero. note that leading_zeros n + unsigned_bitsize n = 64. ๐Ÿงฎ

Since 5.5

  • val leading_sign_bits : t -> 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's an integer between 0 and 63 inclusive. for positive n, it's the number of leading zero bits minus one. for negative n, it's the number of leading one bits minus one. note that leading_sign_bits n + signed_bitsize n = 64. โœจ

Since 5.5

  • val trailing_zeros : t -> int โ€” trailing_zeros n is the number of trailing (least significant) 0 bits in the binary representation of n. it's an integer between 0 and 64 inclusive. it's the largest integer i <= 64 such that 2{^i} divides n evenly. for example, trailing_zeros n = 0 if and only if n is odd, and trailing_zeros n = 64 if and only if n = zero. ๐Ÿ’œ

Since 5.5

  • val seeded_hash : int -> t -> int โ€” a seeded hash function for 64-bit 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 : t -> int

๐Ÿฆ‹ okay so, the hash one (unseeded and unbothered)

bestie, last thing on the page and it's a cute lil one: this is an unseeded hash function for 64-bit ints. No seed, no drama, just vibes โœจ

The iconic part? It gives you the same output value as Hashtbl.hash โ€” like, literally the exact same value. Same energy, same number, no cap ๐Ÿ’…

And the reason that matters (the why, iykyk) is that this identical-output thing is what lets you pass this module as an argument to the functor Hashtbl.Make ๐Ÿซถ So go ahead, hand the whole module over, it's built for it.

genuinely important: the matching output value with Hashtbl.hash isn't a coincidence-y extra, it's the whole point โ€” it's the thing that makes the Hashtbl.Make handoff work. Don't sleep on it ๐Ÿ˜ญ

Since 5.1 โ€” so she's been serving since 5.1, remember that for your notes ๐Ÿ“


and that's the whole page, bestie! ๐ŸŽ€ This lil masterpiece was typeset by OCamldoc, dated 2026-06-22, and it's the Int64(3) page โ€” go forth and hash responsibly ๐Ÿ‘‘๐Ÿ’–๐ŸŒธ

๐Ÿ“ฆ where this page comes from
  • arch rolling: ocaml 5.5.0-1 ยท LGPL2.1 AND custom: QPL-1.0
  • ๐Ÿ’– girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms