Module Base.Int64Source
64-bit integers.
include Base.Int.S with type t := Base.Int64.t
include Sexplib0.Sexpable.S__stack with type t := Base.Int64.t
include Sexplib0.Sexpable.Of_sexp with type t := Base.Int64.t
include Sexplib0.Sexpable.Sexp_of__stack with type t := Base.Int64.t
include Base.Identifiable.S__local__portable with type t := Base.Int64.t
include Sexplib0.Sexpable.S with type t := Base.Int64.t
include Sexplib0.Sexpable.Of_sexp with type t := Base.Int64.t
include Sexplib0.Sexpable.Sexp_of with type t := Base.Int64.t
val sexp_of_t : Base.Int64.t -> Sexplib0.Sexp.tinclude Base.Stringable.S with type t := Base.Int64.t
include Base.Comparable.S__local__portable with type t := Base.Int64.t
include Base.Comparisons.S__local with type t := Base.Int64.t
include Base.Comparisons.Infix with type t := Base.Int64.t
between t ~low ~high means low <= t <= high
val clamp_exn :
Base.Int64.t ->
min:Base.Int64.t ->
max:Base.Int64.t ->
Base.Int64.t @@ portableclamp_exn t ~min ~max returns t', the closest value to t such that between t' ~low:min ~high:max is true.
Raises if not (min <= max).
val clamp :
Base.Int64.t ->
min:Base.Int64.t ->
max:Base.Int64.t ->
Base.Int64.t Base.Or_error.t @@ portableinclude Base.Comparator.S__portable with type t := Base.Int64.t
val comparator :
(Base.Int64.t, Base.Int64.comparator_witness) Base.Comparator.T.comparatorinclude Base.Pretty_printer.S with type t := Base.Int64.t
val pp : Base.Formatter.t -> Base.Int64.t -> unitinclude Base.Comparable.With_zero with type t := Base.Int64.t
val is_positive : Base.Int64.t -> boolval is_non_negative : Base.Int64.t -> boolval is_negative : Base.Int64.t -> boolval is_non_positive : Base.Int64.t -> boolval sign : Base.Int64.t -> Base__.Sign0.tReturns Neg, Zero, or Pos in a way consistent with the above functions.
include Base.Invariant.S with type t := Base.Int64.t
val to_string_hum : ?delimiter:char -> Base.Int64.t @ local -> stringdelimiter is an underscore by default.
Infix operators and constants
Negation
There are two pairs of integer division and remainder functions, /% and %, and / and rem. They both satisfy the same equation relating the quotient and the remainder:
x = (x /% y * y) + (x % y);
x = (x / y * y) + rem x yThe functions return the same values if x and y are positive. They all raise if y = 0.
The functions differ if x < 0 or y < 0.
If y < 0, then % and /% raise, whereas / and rem do not.
x % y always returns a value between 0 and y - 1, even when x < 0. On the other hand, rem x y returns a negative value if and only if x < 0; that value satisfies abs (rem x y) <= abs y - 1.
Other common functions
round rounds an int to a multiple of a given to_multiple_of argument, according to a direction dir, with default dir being `Nearest. round will raise if to_multiple_of <= 0. If the result overflows (too far positive or too far negative), round returns an incorrect result.
| `Down | rounds toward Int.neg_infinity | | `Up | rounds toward Int.infinity | | `Nearest | rounds to the nearest multiple, or `Up in case of a tie | | `Zero | rounds toward zero |
Here are some examples for round ~to_multiple_of:10 for each direction:
| `Down | {10 .. 19} --> 10 | { 0 ... 9} --> 0 | {-10 ... -1} --> -10 |
| `Up | { 1 .. 10} --> 10 | {-9 ... 0} --> 0 | {-19 .. -10} --> -10 |
| `Zero | {10 .. 19} --> 10 | {-9 ... 9} --> 0 | {-19 .. -10} --> -10 |
| `Nearest | { 5 .. 14} --> 10 | {-5 ... 4} --> 0 | {-15 ... -6} --> -10 |For convenience and performance, there are variants of round with dir hard-coded. If you are writing performance-critical code you should use these.
val round :
?dir:[ `Zero | `Nearest | `Up | `Down ] @ local ->
Base.Int64.t @ local ->
to_multiple_of:Base.Int64.t @ local ->
Base.Int64.tval round_towards_zero :
Base.Int64.t @ local ->
to_multiple_of:Base.Int64.t @ local ->
Base.Int64.tval round_down :
Base.Int64.t @ local ->
to_multiple_of:Base.Int64.t @ local ->
Base.Int64.tval round_up :
Base.Int64.t @ local ->
to_multiple_of:Base.Int64.t @ local ->
Base.Int64.tval round_nearest :
Base.Int64.t @ local ->
to_multiple_of:Base.Int64.t @ local ->
Base.Int64.tSuccessor and predecessor functions
Exponentiation
pow base exponent returns base raised to the power of exponent. It is OK if base <= 0. pow raises if exponent < 0, or an integer overflow would occur.
Bit-wise logical operations
These are identical to land, lor, etc. except they're not infix and have different names.
Returns the number of 1 bits in the binary representation of the input.
Bit-shifting operations
The results are unspecified for negative shifts and shifts >= num_bits.
Shifts left, filling in with zeroes.
Shifts right, preserving the sign of the input.
Increment and decrement functions for integer references
Conversion functions to related integer types
of_float_unchecked truncates the given floating point number to an integer, rounding towards zero. The result is unspecified if the argument is nan or falls outside the range of representable integers.
The number of bits available in this integer type. Note that the integer representations are signed.
The largest representable integer.
The smallest representable integer.
Shifts right, filling in with zeroes, which will not preserve the sign of the input.
ceil_pow2 x returns the smallest power of 2 that is greater than or equal to x. The implementation may only be called for x > 0. Example: ceil_pow2 17 = 32
floor_pow2 x returns the largest power of 2 that is less than or equal to x. The implementation may only be called for x > 0. Example: floor_pow2 17 = 16
ceil_log2 x returns the ceiling of log-base-2 of x, and raises if x <= 0.
floor_log2 x returns the floor of log-base-2 of x, and raises if x <= 0.
is_pow2 x returns true iff x is a power of 2. is_pow2 raises if x <= 0.
Returns the number of leading zeros in the binary representation of the input, as an integer between 0 and one less than num_bits.
The results are unspecified for t = 0.
Returns the number of trailing zeros in the binary representation of the input, as an integer between 0 and one less than num_bits.
The results are unspecified for t = 0.
val compare : Base.Int64.t -> Base.Int64.t -> int @@ portableval compare__local : Base.Int64.t -> Base.Int64.t -> int @@ portableval equal : Base.Int64.t -> Base.Int64.t -> bool @@ portableval equal__local : Base.Int64.t -> Base.Int64.t -> bool @@ portableval ascending : Base.Int64.t -> Base.Int64.t -> int @@ portableval descending : Base.Int64.t -> Base.Int64.t -> int @@ portableval max : Base.Int64.t -> Base.Int64.t -> Base.Int64.t @@ portableval min : Base.Int64.t -> Base.Int64.t -> Base.Int64.t @@ portableinclude module type of Base.Int64.O
val (=) : Base.Int64.t -> Base.Int64.t -> boolval (<>) : Base.Int64.t -> Base.Int64.t -> boolval (<) : Base.Int64.t -> Base.Int64.t -> boolval (>) : Base.Int64.t -> Base.Int64.t -> boolval (<=) : Base.Int64.t -> Base.Int64.t -> boolval (>=) : Base.Int64.t -> Base.Int64.t -> boolval (%) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.tval (/%) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.tval (//) : Base.Int64.t @ local -> Base.Int64.t @ local -> floatConversion functions
Truncating conversions
These functions return the least-significant bits of the input. In cases where optional conversions return Some x, truncating conversions return x.
Low-level float conversions
bits_of_float will always allocate its result on the heap unless the _unboxed C function call is chosen by the compiler.
float_of_bits will always allocate its result on the heap unless the _unboxed C function call is chosen by the compiler.
Byte swap operations
See Int's byte swap section for a description of Base's approach to exposing byte swap primitives.
As of writing, these operations do not sign extend unnecessarily on 64 bit machines, unlike their int32 counterparts, and hence, are more performant. See the Int32 module for more details of the overhead entailed by the int32 byteswap functions.