Module Base.Int63Source
63-bit integers.
The size of Int63 is always 63 bits. On a 64-bit platform it is just an int (63-bits), and on a 32-bit platform it is an int64 wrapped to respect the semantics of 63-bit integers.
Because Int63 has different representations on 32-bit and 64-bit platforms, marshalling Int63 will not work between 32-bit and 64-bit platforms -- unmarshal will segfault.
The @@immediate64 attribute is to indicate that t is implemented by a type that is immediate only on 64 bit platforms. It is currently ignored by the compiler, however we are hoping that one day it will be taken into account so that the compiler can omit caml_modify when dealing with mutable data structures holding Int63.t values.
include Sexplib0.Sexpable.S with type t := Base.Int63.t
val t_sexp_grammar : Base.Int63.t Sexplib0.Sexp_grammar.tinclude Base.Floatable.S with type t := Base.Int63.t
val of_float : float -> Base.Int63.tval to_float : Base.Int63.t -> floatinclude Base.Intable.S with type t := Base.Int63.t
val of_int_exn : int -> Base.Int63.tval to_int_exn : Base.Int63.t -> intinclude Base.Identifiable.S with type t := Base.Int63.t
val hash_fold_t : Base.Hash.state -> Base.Int63.t -> Base.Hash.stateval hash : Base.Int63.t -> Base.Hash.hash_valueinclude Sexplib0.Sexpable.S with type t := Base.Int63.t
val t_of_sexp : Sexplib0.Sexp.t -> Base.Int63.tval sexp_of_t : Base.Int63.t -> Sexplib0.Sexp.tinclude Base.Stringable.S with type t := Base.Int63.t
val of_string : string -> Base.Int63.tval to_string : Base.Int63.t -> stringinclude Base.Comparable.S with type t := Base.Int63.t
include Base.Comparisons.S with type t := Base.Int63.t
include Base.Comparisons.Infix with type t := Base.Int63.t
val (>=) : Base.Int63.t -> Base.Int63.t -> boolval (<=) : Base.Int63.t -> Base.Int63.t -> boolval (=) : Base.Int63.t -> Base.Int63.t -> boolval (>) : Base.Int63.t -> Base.Int63.t -> boolval (<) : Base.Int63.t -> Base.Int63.t -> boolval (<>) : Base.Int63.t -> Base.Int63.t -> boolval equal : Base.Int63.t -> Base.Int63.t -> boolval compare : Base.Int63.t -> Base.Int63.t -> intcompare t1 t2 returns 0 if t1 is equal to t2, a negative integer if t1 is less than t2, and a positive integer if t1 is greater than t2.
val min : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval max : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval ascending : Base.Int63.t -> Base.Int63.t -> intascending is identical to compare. descending x y = ascending y x. These are intended to be mnemonic when used like List.sort ~compare:ascending and List.sort ~cmp:descending, since they cause the list to be sorted in ascending or descending order, respectively.
val descending : Base.Int63.t -> Base.Int63.t -> intval between : Base.Int63.t -> low:Base.Int63.t -> high:Base.Int63.t -> boolbetween t ~low ~high means low <= t <= high
val clamp_exn :
Base.Int63.t ->
min:Base.Int63.t ->
max:Base.Int63.t ->
Base.Int63.tclamp_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.Int63.t ->
min:Base.Int63.t ->
max:Base.Int63.t ->
Base.Int63.t Base.Or_error.tinclude Base.Comparator.S with type t := Base.Int63.t
val comparator :
(Base.Int63.t, Base.Int63.comparator_witness) Base.Comparator.comparatorinclude Base.Pretty_printer.S with type t := Base.Int63.t
val pp : Base.Formatter.t -> Base.Int63.t -> unitval hashable : Base.Int63.t Base.Hashable.tinclude Base.Comparable.With_zero with type t := Base.Int63.t
val is_positive : Base.Int63.t -> boolval is_non_negative : Base.Int63.t -> boolval is_negative : Base.Int63.t -> boolval is_non_positive : Base.Int63.t -> boolval sign : Base.Int63.t -> Base.Sign.tReturns Neg, Zero, or Pos in a way consistent with the above functions.
include Base.Invariant.S with type t := Base.Int63.t
val invariant : Base.Int63.t -> unitval of_string_opt : string -> Base.Int63.t optionval to_string_hum : ?delimiter:char -> Base.Int63.t -> stringdelimiter is an underscore by default.
Infix operators and constants
val zero : Base.Int63.tval one : Base.Int63.tval minus_one : Base.Int63.tval (+) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval (-) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval (*) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval (**) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tInteger exponentiation
Negation
val neg : Base.Int63.t -> Base.Int63.tval (~-) : Base.Int63.t -> Base.Int63.tThere 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 y);The 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.
val (/%) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval (%) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval (/) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval rem : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval (//) : Base.Int63.t -> Base.Int63.t -> floatFloat division of integers.
val (land) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tSame as bit_and.
val (lor) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tSame as bit_or.
val (lxor) : Base.Int63.t -> Base.Int63.t -> Base.Int63.tSame as bit_xor.
val lnot : Base.Int63.t -> Base.Int63.tSame as bit_not.
val (lsl) : Base.Int63.t -> int -> Base.Int63.tSame as shift_left.
val (asr) : Base.Int63.t -> int -> Base.Int63.tSame as shift_right.
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 ] ->
Base.Int63.t ->
to_multiple_of:Base.Int63.t ->
Base.Int63.tval round_towards_zero :
Base.Int63.t ->
to_multiple_of:Base.Int63.t ->
Base.Int63.tval round_down : Base.Int63.t -> to_multiple_of:Base.Int63.t -> Base.Int63.tval round_up : Base.Int63.t -> to_multiple_of:Base.Int63.t -> Base.Int63.tval round_nearest : Base.Int63.t -> to_multiple_of:Base.Int63.t -> Base.Int63.tval abs : Base.Int63.t -> Base.Int63.tReturns the absolute value of the argument. May be negative if the input is min_value.
Successor and predecessor functions
val succ : Base.Int63.t -> Base.Int63.tval pred : Base.Int63.t -> Base.Int63.tExponentiation
val pow : Base.Int63.t -> Base.Int63.t -> Base.Int63.tpow 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
val bit_and : Base.Int63.t -> Base.Int63.t -> Base.Int63.tThese are identical to land, lor, etc. except they're not infix and have different names.
val bit_or : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval bit_xor : Base.Int63.t -> Base.Int63.t -> Base.Int63.tval bit_not : Base.Int63.t -> Base.Int63.tval popcount : Base.Int63.t -> intReturns 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.
val shift_left : Base.Int63.t -> int -> Base.Int63.tShifts left, filling in with zeroes.
val shift_right : Base.Int63.t -> int -> Base.Int63.tShifts right, preserving the sign of the input.
Increment and decrement functions for integer references
val decr : Base.Int63.t Stdlib.ref -> unitval incr : Base.Int63.t Stdlib.ref -> unitConversion functions to related integer types
val of_int32_exn : int32 -> Base.Int63.tval to_int32_exn : Base.Int63.t -> int32val of_int64_exn : int64 -> Base.Int63.tval to_int64 : Base.Int63.t -> int64val of_nativeint_exn : nativeint -> Base.Int63.tval to_nativeint_exn : Base.Int63.t -> nativeintval of_float_unchecked : float -> Base.Int63.tof_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.
val max_value : Base.Int63.tThe largest representable integer.
val min_value : Base.Int63.tThe smallest representable integer.
val (lsr) : Base.Int63.t -> int -> Base.Int63.tSame as shift_right_logical.
val shift_right_logical : Base.Int63.t -> int -> Base.Int63.tShifts right, filling in with zeroes, which will not preserve the sign of the input.
val ceil_pow2 : Base.Int63.t -> Base.Int63.tceil_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
val floor_pow2 : Base.Int63.t -> Base.Int63.tfloor_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
val ceil_log2 : Base.Int63.t -> intceil_log2 x returns the ceiling of log-base-2 of x, and raises if x <= 0.
val is_pow2 : Base.Int63.t -> boolis_pow2 x returns true iff x is a power of 2. is_pow2 raises if x <= 0.
val clz : Base.Int63.t -> intReturns 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.
val ctz : Base.Int63.t -> intReturns 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.
A sub-module designed to be opened to make working with ints more convenient.
Arithmetic with overflow
Unlike the usual operations, these never overflow, preferring instead to raise.
Conversion functions
val of_int : int -> Base.Int63.tval to_int : Base.Int63.t -> int optionval of_int32 : Base.Int32.t -> Base.Int63.tval to_int32 : Base.Int63.t -> Base.Int32.t optionval of_int64 : Base.Int64.t -> Base.Int63.t optionval of_nativeint : nativeint -> Base.Int63.t optionval to_nativeint : Base.Int63.t -> nativeint optionTruncating conversions
These functions return the least-significant bits of the input. In cases where optional conversions return Some x, truncating conversions return x.
val to_int_trunc : Base.Int63.t -> intval to_int32_trunc : Base.Int63.t -> Base.Int32.tval of_int64_trunc : Base.Int64.t -> Base.Int63.tval of_nativeint_trunc : nativeint -> Base.Int63.tval to_nativeint_trunc : Base.Int63.t -> nativeintByteswap functions
See Int's byte swap section for a description of Base's approach to exposing byte swap primitives.
val bswap16 : Base.Int63.t -> Base.Int63.tval bswap32 : Base.Int63.t -> Base.Int63.tval bswap48 : Base.Int63.t -> Base.Int63.tRandom generation
random ~state bound returns a random integer between 0 (inclusive) and bound (exclusive). bound must be greater than 0.
The default ~state is Random.State.default.
random_incl ~state lo hi returns a random integer between lo (inclusive) and hi (inclusive). Raises if lo > hi.
The default ~state is Random.State.default.
floor_log2 x returns the floor of log-base-2 of x, and raises if x <= 0.