jon.recoil.org

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.

type t

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.t
include Base.Int.S with type t := Base.Int63.t
val t_sexp_grammar : Base.Int63.t Sexplib0.Sexp_grammar.t @@ portable
include Base.Floatable.S_local_input with type t := Base.Int63.t
val of_float : float @ local -> Base.Int63.t
val to_float : Base.Int63.t @ local -> float
include Base.Intable.S with type t := Base.Int63.t
val of_int_exn : int -> Base.Int63.t
val to_int_exn : Base.Int63.t @ local -> int
include Base.Identifiable.S__local__portable with type t := Base.Int63.t
include Sexplib0.Sexpable.S with type t := Base.Int63.t
include Base.Stringable.S with type t := Base.Int63.t
include Base.Comparable.S__local__portable with type t := Base.Int63.t
val between : Base.Int63.t -> low:Base.Int63.t -> high:Base.Int63.t -> bool @@ portable

between t ~low ~high means low <= t <= high

val clamp_exn : Base.Int63.t -> min:Base.Int63.t -> max:Base.Int63.t -> Base.Int63.t @@ portable

clamp_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 @@ portable
include Base.Pretty_printer.S with type t := Base.Int63.t
val pp : Base.Formatter.t -> Base.Int63.t -> unit
include Base.Stringable.S_local_input with type t := Base.Int63.t
val of_string : string @ local -> Base.Int63.t
val to_string : Base.Int63.t @ local -> string
include Base.Comparable.With_zero with type t := Base.Int63.t
val is_positive : Base.Int63.t -> bool
val is_non_negative : Base.Int63.t -> bool
val is_negative : Base.Int63.t -> bool
val is_non_positive : Base.Int63.t -> bool
val sign : Base.Int63.t -> Base__.Sign0.t

Returns 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 -> unit
Sourcemodule Hex : sig ... end
Sourcemodule Binary : sig ... end
val of_string_opt : string @ local -> Base.Int63.t option
val to_string_hum : ?delimiter:char -> Base.Int63.t @ local -> string

delimiter is an underscore by default.

Infix operators and constants

val zero : Base.Int63.t
val one : Base.Int63.t
val minus_one : Base.Int63.t
val (+) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val (-) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val (*) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val (**) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t

Integer exponentiation

Negation

val neg : Base.Int63.t @ local -> Base.Int63.t
val (~-) : Base.Int63.t @ local -> Base.Int63.t

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 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 @ local -> Base.Int63.t @ local -> Base.Int63.t
val (%) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val (/) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val rem : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val (//) : Base.Int63.t @ local -> Base.Int63.t @ local -> float

Float division of integers.

val (land) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t

Same as bit_and.

val (lor) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t

Same as bit_or.

val (lxor) : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t

Same as bit_xor.

val lnot : Base.Int63.t @ local -> Base.Int63.t

Same as bit_not.

val (lsl) : Base.Int63.t @ local -> int -> Base.Int63.t

Same as shift_left.

val (asr) : Base.Int63.t @ local -> int -> Base.Int63.t

Same 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.t
val round_towards_zero : Base.Int63.t @ local -> to_multiple_of:Base.Int63.t @ local -> Base.Int63.t
val round_down : Base.Int63.t @ local -> to_multiple_of:Base.Int63.t @ local -> Base.Int63.t
val round_up : Base.Int63.t @ local -> to_multiple_of:Base.Int63.t @ local -> Base.Int63.t
val round_nearest : Base.Int63.t @ local -> to_multiple_of:Base.Int63.t @ local -> Base.Int63.t

Returns 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 @ local

Like 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.t
val pred : Base.Int63.t @ local -> Base.Int63.t

Exponentiation

val pow : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t

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

val bit_and : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t

These 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.t
val bit_xor : Base.Int63.t @ local -> Base.Int63.t @ local -> Base.Int63.t
val bit_not : Base.Int63.t @ local -> Base.Int63.t
val popcount : Base.Int63.t @ local -> Base.Int63.t

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.

val shift_left : Base.Int63.t @ local -> int -> Base.Int63.t

Shifts left, filling in with zeroes.

val shift_right : Base.Int63.t @ local -> int -> Base.Int63.t

Shifts right, preserving the sign of the input.

Increment and decrement functions for integer references

val decr : Base.Int63.t Stdlib.ref @ local -> unit
val incr : Base.Int63.t Stdlib.ref @ local -> unit
val of_int32_exn : int32 -> Base.Int63.t
val to_int32_exn : Base.Int63.t -> int32
val to_int64 : Base.Int63.t -> int64
val of_nativeint_exn : nativeint -> Base.Int63.t
val to_nativeint_exn : Base.Int63.t -> nativeint
val of_local_int32_exn : int32 @ local -> Base.Int63.t @ local
val to_local_int32_exn : Base.Int63.t @ local -> int32 @ local
val of_local_int64_exn : int64 @ local -> Base.Int63.t @ local
val to_local_int64 : Base.Int63.t @ local -> int64 @ local
val of_local_nativeint_exn : nativeint @ local -> Base.Int63.t @ local
val to_local_nativeint_exn : Base.Int63.t @ local -> nativeint @ local
val of_float_unchecked : float @ local -> Base.Int63.t

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.

Sourcemodule Summable : sig ... end
val num_bits : Base.Int63.t

The number of bits available in this integer type. Note that the integer representations are signed.

val max_value : Base.Int63.t

The largest representable integer.

val min_value : Base.Int63.t

The smallest representable integer.

val (lsr) : Base.Int63.t @ local -> int -> Base.Int63.t

Same as shift_right_logical.

val shift_right_logical : Base.Int63.t @ local -> int -> Base.Int63.t

Shifts right, filling in with zeroes, which will not preserve the sign of the input.

val ceil_pow2 : Base.Int63.t @ local -> Base.Int63.t

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

val floor_pow2 : Base.Int63.t @ local -> Base.Int63.t

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

val ceil_log2 : Base.Int63.t @ local -> Base.Int63.t

ceil_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.t

floor_log2 x returns the floor of log-base-2 of x, and raises if x <= 0.

val is_pow2 : Base.Int63.t @ local -> bool

is_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.t

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.

val ctz : Base.Int63.t @ local -> Base.Int63.t

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.

Sourcemodule O : sig ... end

A sub-module designed to be opened to make working with ints more convenient.

val (=) : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val (<>) : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val (<) : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val (>) : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val (<=) : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val (>=) : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val compare : Base.Int63.t -> Base.Int63.t -> int @@ portable
val compare__local : Base.Int63.t -> Base.Int63.t -> int @@ portable
val equal : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val equal__local : Base.Int63.t -> Base.Int63.t -> bool @@ portable
val ascending : Base.Int63.t -> Base.Int63.t -> int @@ portable
val descending : Base.Int63.t -> Base.Int63.t -> int @@ portable
val max : Base.Int63.t -> Base.Int63.t -> Base.Int63.t @@ portable
val min : Base.Int63.t -> Base.Int63.t -> Base.Int63.t @@ portable

Arithmetic with overflow

Unlike the usual operations, these never overflow, preferring instead to raise.

Sourcemodule Overflow_exn : sig ... end

Conversion functions

val of_int : int -> Base.Int63.t @@ portable
val to_int : Base.Int63.t @ local -> int option @@ portable
val of_int32 : int32 @ local -> Base.Int63.t @@ portable
val to_int32 : Base.Int63.t @ local -> int32 option @@ portable
val of_int64 : int64 @ local -> Base.Int63.t option @@ portable
val of_int64_exn : int64 @ local -> Base.Int63.t @@ portable
val of_nativeint : nativeint @ local -> Base.Int63.t option @@ portable
val to_nativeint : Base.Int63.t @ local -> nativeint option @@ portable

Truncating 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 @@ portable
val to_int32_trunc : Base.Int63.t @ local -> int32 @@ portable
val of_int64_trunc : int64 @ local -> Base.Int63.t @@ portable
val of_nativeint_trunc : nativeint @ local -> Base.Int63.t @@ portable
val to_nativeint_trunc : Base.Int63.t @ local -> nativeint @@ portable

Byteswap 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 @@ portable
val bswap32 : Base.Int63.t @ local -> Base.Int63.t @@ portable
val bswap48 : Base.Int63.t @ local -> Base.Int63.t @@ portable

Random generation

Sourceval random : ?state:Base.Random.State.t -> Base.Int63.t -> Base.Int63.t @@ portable

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.

Sourceval random_incl : ?state:Base.Random.State.t -> Base.Int63.t -> Base.Int63.t -> Base.Int63.t @@ portable

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.