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.
val globalize : Base.Int63.t @ local -> Base.Int63.tinclude Base.Int.S with type t := Base.Int63.t
include Sexplib0.Sexpable.S__stack with type t := Base.Int63.t
include Sexplib0.Sexpable.Of_sexp with type t := Base.Int63.t
include Sexplib0.Sexpable.Sexp_of__stack with type t := Base.Int63.t
val t_sexp_grammar : Base.Int63.t Sexplib0.Sexp_grammar.t @@ portableinclude Base.Floatable.S_local_input with type t := Base.Int63.t
val of_float : float @ local -> Base.Int63.tval to_float : Base.Int63.t @ local -> floatinclude Base.Intable.S with type t := Base.Int63.t
val of_int_exn : int -> Base.Int63.tval to_int_exn : Base.Int63.t @ local -> intinclude Base.Identifiable.S__local__portable with type t := Base.Int63.t
include Ppx_hash_lib.Hashable.S_any with type t := Base.Int63.t
val hash_fold_t : Base.Int63.t Ppx_hash_lib.hash_foldval hash : Base.Int63.t -> Ppx_hash_lib.Std.Hash.hash_valueinclude Sexplib0.Sexpable.S with type t := Base.Int63.t
include Sexplib0.Sexpable.Of_sexp with type t := Base.Int63.t
val t_of_sexp : Sexplib0.Sexp.t -> Base.Int63.tinclude Sexplib0.Sexpable.Sexp_of with type t := Base.Int63.t
val sexp_of_t : Base.Int63.t -> Sexplib0.Sexp.tinclude Base.Stringable.S with type t := Base.Int63.t
include Base.Comparable.S__local__portable with type t := Base.Int63.t
include Base.Comparisons.S__local with type t := Base.Int63.t
include Base.Comparisons.Infix with type t := Base.Int63.t
val between :
Base.Int63.t ->
low:Base.Int63.t ->
high:Base.Int63.t ->
bool @@ portablebetween t ~low ~high means low <= t <= high
val clamp_exn :
Base.Int63.t ->
min:Base.Int63.t ->
max:Base.Int63.t ->
Base.Int63.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.Int63.t ->
min:Base.Int63.t ->
max:Base.Int63.t ->
Base.Int63.t Base.Or_error.t @@ portableinclude Base.Comparator.S__portable with type t := Base.Int63.t
val comparator :
(Base.Int63.t, Base.Int63.comparator_witness) Base.Comparator.T.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.Stringable.S_local_input with type t := Base.Int63.t
val of_string : string @ local -> Base.Int63.tval to_string : Base.Int63.t @ local -> stringinclude 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__.Sign0.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 @ local -> Base.Int63.t optionval to_string_hum : ?delimiter:char -> Base.Int63.t @ local -> 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 @ local -> Base.Int63.t @ local -> Base.Int63.tval (-) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval (*) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval (**) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tInteger exponentiation
Negation
val neg : Base.Int63.t @ local -> Base.Int63.tval (~-) : Base.Int63.t @ local -> 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 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.
val (/%) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval (%) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval (/) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval rem : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval (//) : Base.Int63.t @ local -> Base.Int63.t @ local -> floatFloat division of integers.
val (land) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tSame as bit_and.
val (lor) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tSame as bit_or.
val (lxor) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tSame as bit_xor.
val lnot : Base.Int63.t @ local -> Base.Int63.tSame as bit_not.
val (lsl) : Base.Int63.t @ local -> int -> Base.Int63.tSame as shift_left.
val (asr) : Base.Int63.t @ local -> 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 ] @ local ->
Base.Int63.t @ local ->
to_multiple_of:Base.Int63.t @ local ->
Base.Int63.tval round_towards_zero :
Base.Int63.t @ local ->
to_multiple_of:Base.Int63.t @ local ->
Base.Int63.tval round_down :
Base.Int63.t @ local ->
to_multiple_of:Base.Int63.t @ local ->
Base.Int63.tval round_up :
Base.Int63.t @ local ->
to_multiple_of:Base.Int63.t @ local ->
Base.Int63.tval round_nearest :
Base.Int63.t @ local ->
to_multiple_of:Base.Int63.t @ local ->
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.
val abs_local : Base.Int63.t @ local -> Base.Int63.t @ localLike abs, but for locally-allocated values. If the argument is already positive, then this is the identity (as is abs itself).
Successor and predecessor functions
val succ : Base.Int63.t @ local -> Base.Int63.tval pred : Base.Int63.t @ local -> Base.Int63.tExponentiation
val pow : Base.Int63.t @ local -> Base.Int63.t @ local -> 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 @ local -> Base.Int63.t @ local -> Base.Int63.tThese are identical to land, lor, etc. except they're not infix and have different names.
val bit_or : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval bit_xor : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.tval bit_not : Base.Int63.t @ local -> Base.Int63.tval popcount : Base.Int63.t @ local -> Base.Int63.tReturns 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 @ local -> int -> Base.Int63.tShifts left, filling in with zeroes.
val shift_right : Base.Int63.t @ local -> 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 @ local -> unitval incr : Base.Int63.t Stdlib.ref @ local -> unitConversion functions to related integer types
val of_int32_exn : int32 -> Base.Int63.tval to_int32_exn : Base.Int63.t -> int32val to_int64 : Base.Int63.t -> int64val of_nativeint_exn : nativeint -> Base.Int63.tval to_nativeint_exn : Base.Int63.t -> nativeintval of_local_int32_exn : int32 @ local -> Base.Int63.t @ localval to_local_int32_exn : Base.Int63.t @ local -> int32 @ localval of_local_int64_exn : int64 @ local -> Base.Int63.t @ localval to_local_int64 : Base.Int63.t @ local -> int64 @ localval of_local_nativeint_exn : nativeint @ local -> Base.Int63.t @ localval to_local_nativeint_exn : Base.Int63.t @ local -> nativeint @ localval of_float_unchecked : float @ local -> 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.
val num_bits : Base.Int63.tThe 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 @ local -> int -> Base.Int63.tSame as shift_right_logical.
val shift_right_logical : Base.Int63.t @ local -> int -> Base.Int63.tShifts right, filling in with zeroes, which will not preserve the sign of the input.
val ceil_pow2 : Base.Int63.t @ local -> 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 @ local -> 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 @ local -> Base.Int63.tceil_log2 x returns the ceiling of log-base-2 of x, and raises if x <= 0.
val floor_log2 : Base.Int63.t @ local -> Base.Int63.tfloor_log2 x returns the floor of log-base-2 of x, and raises if x <= 0.
val is_pow2 : Base.Int63.t @ local -> boolis_pow2 x returns true iff x is a power of 2. is_pow2 raises if x <= 0.
val clz : Base.Int63.t @ local -> Base.Int63.tReturns 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 @ local -> Base.Int63.tReturns 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 (=) : Base.Int63.t -> Base.Int63.t -> bool @@ portableval (<>) : Base.Int63.t -> Base.Int63.t -> bool @@ portableval (<) : Base.Int63.t -> Base.Int63.t -> bool @@ portableval (>) : Base.Int63.t -> Base.Int63.t -> bool @@ portableval (<=) : Base.Int63.t -> Base.Int63.t -> bool @@ portableval (>=) : Base.Int63.t -> Base.Int63.t -> bool @@ portableval compare : Base.Int63.t -> Base.Int63.t -> int @@ portableval compare__local : Base.Int63.t -> Base.Int63.t -> int @@ portableval equal : Base.Int63.t -> Base.Int63.t -> bool @@ portableval equal__local : Base.Int63.t -> Base.Int63.t -> bool @@ portableval ascending : Base.Int63.t -> Base.Int63.t -> int @@ portableval descending : Base.Int63.t -> Base.Int63.t -> int @@ portableval max : Base.Int63.t -> Base.Int63.t -> Base.Int63.t @@ portableval min : Base.Int63.t -> Base.Int63.t -> Base.Int63.t @@ portableArithmetic with overflow
Unlike the usual operations, these never overflow, preferring instead to raise.
Conversion functions
val of_int : int -> Base.Int63.t @@ portableval to_int : Base.Int63.t @ local -> int option @@ portableval of_int32 : int32 @ local -> Base.Int63.t @@ portableval to_int32 : Base.Int63.t @ local -> int32 option @@ portableval of_int64 : int64 @ local -> Base.Int63.t option @@ portableval of_int64_exn : int64 @ local -> Base.Int63.t @@ portableval of_nativeint : nativeint @ local -> Base.Int63.t option @@ portableval to_nativeint : Base.Int63.t @ local -> nativeint option @@ portableTruncating 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 @ local -> int @@ portableval to_int32_trunc : Base.Int63.t @ local -> int32 @@ portableval of_int64_trunc : int64 @ local -> Base.Int63.t @@ portableval of_nativeint_trunc : nativeint @ local -> Base.Int63.t @@ portableval to_nativeint_trunc : Base.Int63.t @ local -> nativeint @@ portableByteswap functions
See Int's byte swap section for a description of Base's approach to exposing byte swap primitives.
val bswap16 : Base.Int63.t @ local -> Base.Int63.t @@ portableval bswap32 : Base.Int63.t @ local -> Base.Int63.t @@ portableval bswap48 : Base.Int63.t @ local -> Base.Int63.t @@ portableRandom 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.
val random_incl :
?state:Base.Random.State.t ->
Base.Int63.t ->
Base.Int63.t ->
Base.Int63.t @@ portablerandom_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.