jon.recoil.org

Module Base.Int64Source

64-bit integers.

Sourcetype t = int64
Sourceval globalize : Base.Int64.t @ local -> Base.Int64.t
include Base.Int.S with type t := Base.Int64.t
Sourceval t_sexp_grammar : Base.Int64.t Sexplib0.Sexp_grammar.t @@ portable
include Base.Floatable.S_local_input with type t := Base.Int64.t
Sourceval of_float : float @ local -> Base.Int64.t
Sourceval to_float : Base.Int64.t @ local -> float
include Base.Intable.S with type t := Base.Int64.t
Sourceval of_int_exn : int -> Base.Int64.t
Sourceval to_int_exn : Base.Int64.t @ local -> int
include Base.Identifiable.S__local__portable with type t := Base.Int64.t
include Base.Stringable.S with type t := Base.Int64.t
include Base.Comparable.S__local__portable with type t := Base.Int64.t
Sourceval between : Base.Int64.t -> low:Base.Int64.t -> high:Base.Int64.t -> bool @@ portable

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

Sourceval clamp_exn : Base.Int64.t -> min:Base.Int64.t -> max:Base.Int64.t -> Base.Int64.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).

include Base.Pretty_printer.S with type t := Base.Int64.t
val pp : Base.Formatter.t -> Base.Int64.t -> unit
include Base.Stringable.S_local_input with type t := Base.Int64.t
Sourceval of_string : string @ local -> Base.Int64.t
Sourceval to_string : Base.Int64.t @ local -> string
include Base.Comparable.With_zero with type t := Base.Int64.t
val is_positive : Base.Int64.t -> bool
val is_non_negative : Base.Int64.t -> bool
val is_negative : Base.Int64.t -> bool
val is_non_positive : Base.Int64.t -> bool
val sign : Base.Int64.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.Int64.t
Sourceval invariant : Base.Int64.t -> unit
Sourcemodule Hex : sig ... end
Sourcemodule Binary : sig ... end
Sourceval of_string_opt : string @ local -> Base.Int64.t option
val to_string_hum : ?delimiter:char -> Base.Int64.t @ local -> string

delimiter is an underscore by default.

Infix operators and constants

Sourceval minus_one : Base.Int64.t

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

Sourceval rem : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t

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

Successor and predecessor functions

Sourceval succ : Base.Int64.t @ local -> Base.Int64.t
Sourceval pred : Base.Int64.t @ local -> Base.Int64.t

Exponentiation

Sourceval pow : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.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

Sourceval bit_and : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t

These are identical to land, lor, etc. except they're not infix and have different names.

Sourceval bit_or : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval bit_xor : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval bit_not : Base.Int64.t @ local -> Base.Int64.t
Sourceval popcount : Base.Int64.t @ local -> Base.Int64.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.

Sourceval shift_left : Base.Int64.t @ local -> int -> Base.Int64.t

Shifts left, filling in with zeroes.

Sourceval shift_right : Base.Int64.t @ local -> int -> Base.Int64.t

Shifts right, preserving the sign of the input.

Increment and decrement functions for integer references

Sourceval decr : Base.Int64.t Stdlib.ref @ local -> unit
Sourceval incr : Base.Int64.t Stdlib.ref @ local -> unit
Sourceval of_int32_exn : int32 -> Base.Int64.t
Sourceval to_int32_exn : Base.Int64.t -> int32
Sourceval of_int64_exn : int64 -> Base.Int64.t
Sourceval to_int64 : Base.Int64.t -> int64
Sourceval of_nativeint_exn : nativeint -> Base.Int64.t
Sourceval to_nativeint_exn : Base.Int64.t -> nativeint
Sourceval of_local_int32_exn : int32 @ local -> Base.Int64.t @ local
Sourceval to_local_int32_exn : Base.Int64.t @ local -> int32 @ local
Sourceval of_local_int64_exn : int64 @ local -> Base.Int64.t @ local
Sourceval to_local_int64 : Base.Int64.t @ local -> int64 @ local
Sourceval of_local_nativeint_exn : nativeint @ local -> Base.Int64.t @ local
Sourceval to_local_nativeint_exn : Base.Int64.t @ local -> nativeint @ local
Sourceval of_float_unchecked : float @ local -> Base.Int64.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
Sourceval num_bits : Base.Int64.t

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

Sourceval max_value : Base.Int64.t

The largest representable integer.

Sourceval min_value : Base.Int64.t

The smallest representable integer.

Sourceval shift_right_logical : Base.Int64.t @ local -> int -> Base.Int64.t

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

Sourceval ceil_pow2 : Base.Int64.t @ local -> Base.Int64.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

Sourceval floor_pow2 : Base.Int64.t @ local -> Base.Int64.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

Sourceval ceil_log2 : Base.Int64.t @ local -> Base.Int64.t

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

Sourceval floor_log2 : Base.Int64.t @ local -> Base.Int64.t

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

Sourceval is_pow2 : Base.Int64.t @ local -> bool

is_pow2 x returns true iff x is a power of 2. is_pow2 raises if x <= 0.

Sourceval clz : Base.Int64.t @ local -> Base.Int64.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.

Sourceval ctz : Base.Int64.t @ local -> Base.Int64.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.

val compare : Base.Int64.t -> Base.Int64.t -> int @@ portable
val compare__local : Base.Int64.t -> Base.Int64.t -> int @@ portable
val equal : Base.Int64.t -> Base.Int64.t -> bool @@ portable
val equal__local : Base.Int64.t -> Base.Int64.t -> bool @@ portable
val ascending : Base.Int64.t -> Base.Int64.t -> int @@ portable
val descending : Base.Int64.t -> Base.Int64.t -> int @@ portable
val max : Base.Int64.t -> Base.Int64.t -> Base.Int64.t @@ portable
val min : Base.Int64.t -> Base.Int64.t -> Base.Int64.t @@ portable
Sourcemodule O : sig ... end
include module type of Base.Int64.O
Sourceval (+) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval (-) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval (*) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval (/) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval (~-) : Base.Int64.t @ local -> Base.Int64.t
Sourceval (**) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
val (=) : Base.Int64.t -> Base.Int64.t -> bool
val (<>) : Base.Int64.t -> Base.Int64.t -> bool
val (<) : Base.Int64.t -> Base.Int64.t -> bool
val (>) : Base.Int64.t -> Base.Int64.t -> bool
val (<=) : Base.Int64.t -> Base.Int64.t -> bool
val (>=) : Base.Int64.t -> Base.Int64.t -> bool
Sourceval (land) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval (lor) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval (lxor) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
Sourceval lnot : Base.Int64.t @ local -> Base.Int64.t
Sourceval abs_local : Base.Int64.t @ local -> Base.Int64.t @ local
Sourceval neg : Base.Int64.t @ local -> Base.Int64.t
val (%) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
val (/%) : Base.Int64.t @ local -> Base.Int64.t @ local -> Base.Int64.t
val (//) : Base.Int64.t @ local -> Base.Int64.t @ local -> float
Sourceval (lsl) : Base.Int64.t @ local -> int -> Base.Int64.t
Sourceval (asr) : Base.Int64.t @ local -> int -> Base.Int64.t
Sourceval (lsr) : Base.Int64.t @ local -> int -> Base.Int64.t

Conversion functions

Sourceval of_int : int -> Base.Int64.t @@ portable
Sourceval of_int32 : int32 @ local -> Base.Int64.t @@ portable
Sourceval of_int64 : Base.Int64.t -> Base.Int64.t @@ portable
Sourceval to_int : Base.Int64.t @ local -> int option @@ portable
Sourceval to_int32 : Base.Int64.t @ local -> int32 option @@ portable
Sourceval of_nativeint : nativeint @ local -> Base.Int64.t @@ portable
Sourceval to_nativeint : Base.Int64.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.

Sourceval to_int_trunc : Base.Int64.t @ local -> int @@ portable
Sourceval to_int32_trunc : Base.Int64.t @ local -> int32 @@ portable
Sourceval to_nativeint_trunc : Base.Int64.t @ local -> nativeint @@ portable

Low-level float conversions

Sourceval bits_of_float : float @ local -> Base.Int64.t @@ portable

bits_of_float will always allocate its result on the heap unless the _unboxed C function call is chosen by the compiler.

Sourceval float_of_bits : Base.Int64.t @ local -> float @@ portable

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.

Sourceval bswap16 : Base.Int64.t @ local -> Base.Int64.t @@ portable
Sourceval bswap32 : Base.Int64.t @ local -> Base.Int64.t @@ portable
Sourceval bswap48 : Base.Int64.t @ local -> Base.Int64.t @@ portable
Sourceval bswap64 : Base.Int64.t @ local -> Base.Int64.t @@ portable