package checked_oint

  1. Overview
  2. Docs

The signature of operations on integers.

type t

The particular integer type.

The bitwise operations bit_not, bit_or, bit_and, bit_xor, shift_left, and shift_right assume that signed integers are represented in the two's complement notation.

NOTE: implementations may not support polymorphic comparison operators. Use equal and compare instead.

val equal : t -> t -> Ppx_deriving_runtime.bool
val compare : t -> t -> Ppx_deriving_runtime.int
val bits : int

The number of bits of this integer type.

val zero : t

The value of 0.

val one : t

The value of 1.

val all_ones : t

The value that has all bits set to 1.

val min_int : t

The minimum value of this type.

val max_int : t

The maximum value of this type.

val is_signed : bool

Whether this integer type is signed or not.

val of_int_exn : int -> t

Constructs a value out of int; raises Out_of_range on overflow/underflow.

val of_string_exn : string -> t

Constructs a value out of string; raises Out_of_range on overflow/underflow.

We allow the following classes of non-negative integers:

  • Binary: 0b (0B) followed by a non-empty sequence of binary digits 0 and 1.
  • Octal: 0o (0O) followed by a non-empty sequence of octal digits 0, ..., 7.
  • Decimal: a non-empty sequence of decimal digits 0, ..., 9.
  • Hexadecimal: 0x (0X) followed by a non-empty sequence of decimal digits 0, ..., 9 and letters a, ..., f (A, ..., F).

(Currently, 128-bit integers can only be decimal.)

A negative integer is described by the - character followed by a well-formed non-negative integer.

All other combinations of characters will raise Out_of_range.

val succ : t -> t option

Finds a successor; returns None on overflow.

val pred : t -> t option

Finds a predecessor; returns None on underflow.

val neg : t -> t option

Performs unary negation; returns None on overflow/underflow.

val abs : t -> t option

Finds an absolute value; returns None on overflow.

val add : t -> t -> t option

Performs addition; returns None on overflow/underflow.

val sub : t -> t -> t option

Performs subtraction; returns None on overflow/underflow.

val mul : t -> t -> t option

Performs multiplication; returns None on overflow/underflow.

val div : t -> t -> t option

Performs division; returns None on overflow/underflow.

val rem : t -> t -> t option

Finds a remainder; returns None on overflow/underflow.

val bit_not : t -> t

Performs bitwise negation.

val bit_or : t -> t -> t

Performs bitwise disjunction.

val bit_and : t -> t -> t

Performs bitwise conjunction.

val bit_xor : t -> t -> t

Performs bitwise exclusive disjunction.

val shift_left : t -> t -> t option

Performs left shifting; returns None on overflow/underflow.

val shift_right : t -> t -> t option

Performs right shifting; returns None on overflow/underflow.

This is a logical shift for unsigned integer types and arithmetic shift for signed integer types.

val min : t -> t -> t

Finds the minimum integer of two.

val max : t -> t -> t

Finds the maximum integer of two.

val succ_exn : t -> t

Finds a successor; raises Out_of_range on overflow.

val pred_exn : t -> t

Finds a predecessor; raises Out_of_range on underflow.

val neg_exn : t -> t

Performs unary negation; raises Out_of_range on overflow/underflow.

val abs_exn : t -> t

Finds an absolute value; raises Out_of_range on overflow.

val add_exn : t -> t -> t

Performs addition; raises Out_of_range on overflow/underflow.

val sub_exn : t -> t -> t

Performs subtraction; raises Out_of_range on overflow/underflow.

val mul_exn : t -> t -> t

Performs multiplication; raises Out_of_range on overflow/underflow.

val div_exn : t -> t -> t

Performs division; raises Out_of_range on overflow/underflow.

val rem_exn : t -> t -> t

Finds a remainder; raises Out_of_range on overflow/underflow.

val shift_left_exn : t -> t -> t

Performs left shifting; raises Out_of_range on overflow/underflow.

val shift_right_exn : t -> t -> t

Performs right shifting; raises Out_of_range on overflow/underflow.

This is a logical shift for unsigned integer types and arithmetic shift for signed integer types.

val to_string : t -> string

Prints a value in decimal; same as show.

val to_generic : t -> generic

Casts a value into generic.

OCaml

Innovation. Community. Security.