Module Stdint.Uint128
type t
= uint128
The specific integer type
val zero : t
The value
0
val one : t
The value
1
val max_int : t
The greatest representable integer
val min_int : t
The smallest representable integer; for unsigned integers this is
zero
.
val (/) : t -> t -> t
Integer division. Raise
Division_by_zero
if the second argument is zero. This division rounds the real quotient of its arguments towards zero, as specified for(/)
.
val div : t -> t -> t
Integer division. Raise
Division_by_zero
if the second argument is zero. This division rounds the real quotient of its arguments towards zero, as specified for(/)
.
val rem : t -> t -> t
Integer remainder. If
y
is notzero
, the result ofrem x y
satisfies the following property:x = add (mul (div x y) y) (rem x y)
. Ify = 0
,rem x y
raisesDivision_by_zero
.
val shift_left : t -> int -> t
shift_left x y
shiftsx
to the left byy
bits. The result is unspecified ify < 0
ory >= bits
.
val shift_right : t -> int -> t
shift_right x y
shiftsx
to the right byy
bits. If this is a signed integer, this is an arithmetic shift: the sign bit ofx
is replicated and inserted in the vacated bits. The result is unspecified ify < 0
ory >= bits
. For an unsigned integer, this is identical toshift_right_logical
.
val shift_right_logical : t -> int -> t
shift_right_logical x y
shiftsx
to the right byy
bits. This is a logical shift: zeroes are inserted in the vacated bits regardless ifx
is a signed or unsiged integer. The result is unspecified ify < 0
ory >= bits
.
val of_int : int -> t
Convert the given integer (type
int
) to this integer type.
val to_int : t -> int
Convert the given integer (type
t
) to an integer of typeint
.
val of_float : float -> t
Convert the given floating-point number to an integer of type
t
.
val to_float : t -> float
Convert the given integer to a floating-point number.
val of_nativeint : nativeint -> t
Convert the given integer (type
t
) to a native integer.
val to_nativeint : t -> nativeint
Convert the given native integer (type
nativeint
) to an integer (typet
.
val of_substring : string -> pos:int -> t * int
Convert the given substring starting at the given offset
pos
to an integer of typet
and return the offset. The string is read in decimal (by default) or in hexadecimal, octal or binary if the string begins with0x
,0o
or0b
respectively. RaiseFailure "*_of_substring"
if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in typet
.
val of_string : string -> t
Convert the given string to an integer of type
t
. The string is read in decimal (by default) or in hexadecimal, octal or binary if the string begins with0x
,0o
or0b
respectively. RaiseFailure "*_of_string"
if the given string is not a valid representation of an integer, or if the integer represented exceeds the range of integers representable in typet
.
val to_string : t -> string
Return the string representation of its argument, in decimal.
val to_string_bin : t -> string
Return the string representation of its argument, in binary (beginning with
0b
)
val to_string_oct : t -> string
Return the string representation of its argument, in octal (beginning with
0o
)
val to_string_hex : t -> string
Return the string representation of its argument, in hex (beginning with
0x
)
val printer : Stdlib.Format.formatter -> t -> unit
val printer_bin : Stdlib.Format.formatter -> t -> unit
val printer_oct : Stdlib.Format.formatter -> t -> unit
val printer_hex : Stdlib.Format.formatter -> t -> unit
val of_bytes_big_endian : Stdlib.Bytes.t -> int -> t
of_bytes_big_endian buffer offset
creates an integer value of typet
from the bufferbuffer
starting at offsetoffset
. The byte order is interpreted to be big endian. If the buffer does not hold enough bytes for this integer, i.e. if(Bytes.length buffer) < (offset + (bits / 8))
, the function will raiseInvalid_argument "index out of bounds"
.
val of_bytes_little_endian : Stdlib.Bytes.t -> int -> t
of_bytes_big_endian buffer offset
creates an integer value of typet
from the bufferbuffer
starting at offsetoffset
. The byte order is interpreted to be little endian. If the buffer does not hold enough bytes for this integer, i.e. if(Bytes.length buffer) < (offset + (bits / 8))
, the function will raiseInvalid_argument "index out of bounds"
.
val to_bytes_big_endian : t -> Stdlib.Bytes.t -> int -> unit
to_bytes_big_endian i buffer offset
writes the integeri
to the bufferbuffer
starting at offsetoffset
. The byte order used is big endian. If the buffer does not hold enough bytes, i.e. if(Bytes.length buffer) < (offset + (bits / 8))
, the function will raiseInvalid_argument "index out of bounds"
.
val to_bytes_little_endian : t -> Stdlib.Bytes.t -> int -> unit
to_bytes_little_endian i buffer offset
writes the integeri
to the bufferbuffer
starting at offsetoffset
. The byte order used is little endian. If the buffer does not hold enough bytes, i.e. if(Bytes.length buffer) < (offset + (bits / 8))
, the function will raiseInvalid_argument "index out of bounds"
.