Module Checked_oint

checked_oint is an OCaml library for checked integer arithmetic.

This library supports signed and unsigned integers of bitnesses 8, 16, 32, 64, and 128. S is the main signature that contains common operations for all integer types; specific implementations are named U8, U16, and so on.

Polymorphic comparison operators raise Invalid_argument by default; use S.equal and S.compare instead. This behaviour is controlled by the checked_oint.guard virtual library; see the README.

exception Out_of_range

The exception raised on underflows/overflows.

type u8

An unsigned 8-bit integer.

val equal_u8 : u8 -> u8 -> Ppx_deriving_runtime.bool
val pp_u8 : Ppx_deriving_runtime.Format.formatter -> u8 -> Ppx_deriving_runtime.unit
val show_u8 : u8 -> Ppx_deriving_runtime.string
val compare_u8 : u8 -> u8 -> Ppx_deriving_runtime.int
type u16

An unsigned 16-bit integer.

val equal_u16 : u16 -> u16 -> Ppx_deriving_runtime.bool
val pp_u16 : Ppx_deriving_runtime.Format.formatter -> u16 -> Ppx_deriving_runtime.unit
val show_u16 : u16 -> Ppx_deriving_runtime.string
val compare_u16 : u16 -> u16 -> Ppx_deriving_runtime.int
type u32

An unsigned 32-bit integer.

val equal_u32 : u32 -> u32 -> Ppx_deriving_runtime.bool
val pp_u32 : Ppx_deriving_runtime.Format.formatter -> u32 -> Ppx_deriving_runtime.unit
val show_u32 : u32 -> Ppx_deriving_runtime.string
val compare_u32 : u32 -> u32 -> Ppx_deriving_runtime.int
type u64

An unsigned 64-bit integer.

val equal_u64 : u64 -> u64 -> Ppx_deriving_runtime.bool
val pp_u64 : Ppx_deriving_runtime.Format.formatter -> u64 -> Ppx_deriving_runtime.unit
val show_u64 : u64 -> Ppx_deriving_runtime.string
val compare_u64 : u64 -> u64 -> Ppx_deriving_runtime.int
type u128

An unsigned 128-bit integer.

val equal_u128 : u128 -> u128 -> Ppx_deriving_runtime.bool
val pp_u128 : Ppx_deriving_runtime.Format.formatter -> u128 -> Ppx_deriving_runtime.unit
val show_u128 : u128 -> Ppx_deriving_runtime.string
val compare_u128 : u128 -> u128 -> Ppx_deriving_runtime.int
type i8

A signed 8-bit integer.

val equal_i8 : i8 -> i8 -> Ppx_deriving_runtime.bool
val pp_i8 : Ppx_deriving_runtime.Format.formatter -> i8 -> Ppx_deriving_runtime.unit
val show_i8 : i8 -> Ppx_deriving_runtime.string
val compare_i8 : i8 -> i8 -> Ppx_deriving_runtime.int
type i16

A signed 16-bit integer.

val equal_i16 : i16 -> i16 -> Ppx_deriving_runtime.bool
val pp_i16 : Ppx_deriving_runtime.Format.formatter -> i16 -> Ppx_deriving_runtime.unit
val show_i16 : i16 -> Ppx_deriving_runtime.string
val compare_i16 : i16 -> i16 -> Ppx_deriving_runtime.int
type i32

A signed 32-bit integer.

val equal_i32 : i32 -> i32 -> Ppx_deriving_runtime.bool
val pp_i32 : Ppx_deriving_runtime.Format.formatter -> i32 -> Ppx_deriving_runtime.unit
val show_i32 : i32 -> Ppx_deriving_runtime.string
val compare_i32 : i32 -> i32 -> Ppx_deriving_runtime.int
type i64

A signed 64-bit integer.

val equal_i64 : i64 -> i64 -> Ppx_deriving_runtime.bool
val pp_i64 : Ppx_deriving_runtime.Format.formatter -> i64 -> Ppx_deriving_runtime.unit
val show_i64 : i64 -> Ppx_deriving_runtime.string
val compare_i64 : i64 -> i64 -> Ppx_deriving_runtime.int
type i128

A signed 128-bit integer.

val equal_i128 : i128 -> i128 -> Ppx_deriving_runtime.bool
val pp_i128 : Ppx_deriving_runtime.Format.formatter -> i128 -> Ppx_deriving_runtime.unit
val show_i128 : i128 -> Ppx_deriving_runtime.string
val compare_i128 : i128 -> i128 -> Ppx_deriving_runtime.int
module Int_ty : sig ... end

Represents a materialized integer type.

type value =
  1. | Value : 'a Int_ty.t * 'a -> value

An integer of an arbitrary type.

val equal_value : value -> value -> Ppx_deriving_runtime.bool
val pp_value : Ppx_deriving_runtime.Format.formatter -> value -> Ppx_deriving_runtime.unit
val show_value : value -> Ppx_deriving_runtime.string
val is_zero : value -> bool

true if the integer is 0, false otherwise.

val is_one : value -> bool

true if the integer is 1, false otherwise.

val is_all_ones : value -> bool

true if the integer has all bits set to 1, false otherwise.

module type S = sig ... end

The signature of operations on integers.

module U8 : S with type t = u8

The implementation of u8.

module U16 : S with type t = u16

The implementation of u16.

module U32 : S with type t = u32

The implementation of u32.

module U64 : S with type t = u64

The implementation of u64.

module U128 : sig ... end

The implementation of u128.

module I8 : S with type t = i8

The implementation of i8.

module I16 : S with type t = i16

The implementation of i16.

module I32 : S with type t = i32

The implementation of i32.

module I64 : S with type t = i64

The implementation of i64.

module I128 : sig ... end

The implementation of i128.

val ops : 'a Int_ty.t -> (module S with type t = 'a)

Finds an integer implementation based on its type representation.