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 typeint64take up more memory space than values of typeint, and arithmetic operations onint64are generally slower than the ones onint. so only useint64when your application actually requires exact 64-bit arithmetic, okay? don't be out here choosingint64for 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 integer0. the origin story โจval one : int64โ the 64-bit integer1. 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.
๐ซถ raisesDivision_by_zeroif 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 asInt64.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. ifyis not zero, then the result ofInt64.rem x ysatisfies 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 asInt64.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 yis the real quotientx / yrounded down to an integer. we havefdiv x y <= div x y <= cdiv x yandcdiv x y - fdiv x y <= 1. ๐ฆ
Since 5.5
raisesDivision_by_zeroif the second argument is0.
val cdiv : int64 -> int64 -> int64โ ceil division.cdiv x yis the real quotientx / yrounded up to an integer. we havefdiv x y <= div x y <= cdiv x yandcdiv x y - fdiv x y <= 1. ๐ธ
Since 5.5
raisesDivision_by_zeroif the second argument is0.
val ediv : int64 -> int64 -> int64โ Euclidean division.ediv x yis the real quotientx / yrounded down to an integer ify > 0and rounded up to an integer ify < 0. the remaindererem x y = x - ediv x y * yis always non-negative. and moreover (fancy word, i know),ediv x (-y) = - ediv x y. ๐
Since 5.5
raisesDivision_by_zeroif the second argument is0.
val erem : int64 -> int64 -> int64โ Euclidean remainder. ifyis not zero, we havex = ediv x y * y + erem x yand0 <= erem x y <= abs y - 1. the result oferem x yis always non-negative, unlike the result ofrem x y, which has the sign ofx. that's the whole plot twist right there ๐ญ
Since 5.5
raisesDivision_by_zeroif the second argument is0.
val succ : int64 -> int64โ successor.Int64.succ xisInt64.add x Int64.one. she's giving next.val pred : int64 -> int64โ predecessor.Int64.pred xisInt64.sub x Int64.one. she's giving previous. main character energy both ways ๐ฅval abs : int64 -> int64โabs xis the absolute value ofx. but bestie, listen: onmin_intthis ismin_intitself 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 yshiftsxto the left byybits.
๐จ the result is unspecified ify < 0ory >= 64. undefined-ish behavior is not a vibe, don't do it.
val shift_right : int64 -> int -> int64โInt64.shift_right x yshiftsxto the right byybits. this one's an arithmetic shift: the sign bit ofxis replicated and inserted in the vacated bits.
๐จ the result is unspecified ify < 0ory >= 64.
val shift_right_logical : int64 -> int -> int64โInt64.shift_right_logical x yshiftsxto the right byybits. this one's a logical shift: zeroes are inserted in the vacated bits regardless of the sign ofx.
๐จ the result is unspecified ify < 0ory >= 64.
๐ conversions ๐
val of_int : int -> int64โ convert the given integer (typeint) to a 64-bit integer (typeint64).val to_int : int64 -> intโ convert the given 64-bit integer (typeint64) to an integer (typeint). on 64-bit platforms, the 64-bit integer is taken modulo2^63, i.e. the high-order bit is lost during the conversion. on 32-bit platforms, the 64-bit integer is taken modulo2^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 asInt64.to_int, but interprets the argument as an unsigned integer. returnsNoneif the unsigned value of the argument cannot fit into anint.
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 (typeint32) to a 64-bit integer (typeint64). glow-up.val to_int32 : int64 -> int32โ convert the given 64-bit integer (typeint64) to a 32-bit integer (typeint32). the 64-bit integer is taken modulo2^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 (typenativeint) to a 64-bit integer (typeint64).val to_nativeint : int64 -> nativeintโ convert the given 64-bit integer (typeint64) to a native integer. on 32-bit platforms, the 64-bit integer is taken modulo2^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 with0u) or in hexadecimal, octal or binary if the string begins with0x,0oor0brespectively.
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 ๐
raisesFailureif the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in typeint64.
val of_string_opt : string -> int64 optionโ same asof_string, but returnsNoneinstead 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 givenfloataccording to the IEEE 754 floating-point 'double format' bit layout. bit 63 of the result represents the sign of thefloat; 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 givenint64.
๐ 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 ascompare. along with the typet, this functioncompareallows the moduleInt64to be passed as argument to the functorsSet.MakeandMap.Make. she's plug-and-play, we stan ๐ซถval unsigned_compare : t -> t -> intโ same asInt64.compare, except that the arguments are interpreted as unsigned 64-bit integers.
Since 4.08
val equal : t -> t -> boolโ theequalfunction forint64s.
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 nis the number of1bits in the binary representation ofn. negativenare 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 nis the minimal number of bits needed to representnas an unsigned binary number. it's the smallest integeribetween0and64inclusive such that0 <= n < 2{^i}(unsigned).
Since 5.5
val signed_bitsize : t -> intโsigned_bitsize nis the minimal number of bits needed to representnas a signed, two's complement binary number. it's the smallest integeribetween1and64inclusive such that-2{^i-1} <= n < 2{^i-1}(signed).
Since 5.5
val leading_zeros : t -> intโleading_zeros nis the number of leading (most significant)0bits in the binary representation ofn. it's an integer between0and64inclusive. ifnis negative,leading_zeros n = 0since the most significant bit ofnis1.leading_zeros n = 64if and only ifn = zero. note thatleading_zeros n + unsigned_bitsize n = 64. ๐งฎ
Since 5.5
val leading_sign_bits : t -> intโleading_sign_bits nis the number of leading (most significant) sign bits in the binary representation ofn, excluding the sign bit itself. it's an integer between0and63inclusive. for positiven, it's the number of leading zero bits minus one. for negativen, it's the number of leading one bits minus one. note thatleading_sign_bits n + signed_bitsize n = 64. โจ
Since 5.5
val trailing_zeros : t -> intโtrailing_zeros nis the number of trailing (least significant)0bits in the binary representation ofn. it's an integer between0and64inclusive. it's the largest integeri <= 64such that2{^i}dividesnevenly. for example,trailing_zeros n = 0if and only ifnis odd, andtrailing_zeros n = 64if and only ifn = zero. ๐
Since 5.5
val seeded_hash : int -> t -> intโ a seeded hash function for 64-bit ints, with the same output value asHashtbl.seeded_hash. this function allows this module to be passed as argument to the functorHashtbl.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 withHashtbl.hashisn't a coincidence-y extra, it's the whole point โ it's the thing that makes theHashtbl.Makehandoff 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