package checked_oint

  1. Overview
  2. Docs

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.

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 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 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 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 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 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 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 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 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 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 compare_i128 : i128 -> i128 -> Ppx_deriving_runtime.int
type generic =
  1. | U8 of u8
  2. | U16 of u16
  3. | U32 of u32
  4. | U64 of u64
  5. | U128 of u128
  6. | I8 of i8
  7. | I16 of i16
  8. | I32 of i32
  9. | I64 of i64
  10. | I128 of i128

A type that can hold any fixed-width integer.

val equal_generic : generic -> generic -> Ppx_deriving_runtime.bool
val pp_generic : Ppx_deriving_runtime.Format.formatter -> generic -> Ppx_deriving_runtime.unit
val show_generic : generic -> Ppx_deriving_runtime.string
type signedness =
  1. | Unsigned
  2. | Signed

Represents integer signedness.

val equal_signedness : signedness -> signedness -> Ppx_deriving_runtime.bool
val pp_signedness : Ppx_deriving_runtime.Format.formatter -> signedness -> Ppx_deriving_runtime.unit
val show_signedness : signedness -> Ppx_deriving_runtime.string
val all_of_signedness : signedness list
type bitness =
  1. | Bits8
  2. | Bits16
  3. | Bits32
  4. | Bits64
  5. | Bits128

Represents integer bitness.

val equal_bitness : bitness -> bitness -> Ppx_deriving_runtime.bool
val pp_bitness : Ppx_deriving_runtime.Format.formatter -> bitness -> Ppx_deriving_runtime.unit
val show_bitness : bitness -> Ppx_deriving_runtime.string
val all_of_bitness : bitness list
type int_ty = signedness * bitness

Represents an integer type.

val equal_int_ty : int_ty -> int_ty -> Ppx_deriving_runtime.bool
val pp_int_ty : Ppx_deriving_runtime.Format.formatter -> int_ty -> Ppx_deriving_runtime.unit
val show_int_ty : int_ty -> Ppx_deriving_runtime.string
val all_of_int_ty : int_ty list
include sig ... end
val u8_int_ty : int_ty
val u16_int_ty : int_ty
val u32_int_ty : int_ty
val u64_int_ty : int_ty
val u128_int_ty : int_ty
val i8_int_ty : int_ty
val i16_int_ty : int_ty
val i32_int_ty : int_ty
val i64_int_ty : int_ty
val i128_int_ty : int_ty
val generic_int_ty : generic -> int_ty

Determines the type representation of a generic integer.

val is_zero : generic -> bool

true if the integer is 0, false otherwise.

val is_one : generic -> bool

true if the integer is 1, false otherwise.

val is_all_ones : generic -> 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 : int_ty -> (module S)

Finds an integer implementation based on its type representation.

module type Singleton = sig ... end

A single integer of an arbitrary type.

val singleton : generic -> (module Singleton)

Constructs an integer singleton.

module type Pair = sig ... end

A pair of integers of an arbitrary type.

val pair_exn : (generic * generic) -> (module Pair)

Constructs a pair of integers; raises Invalid_argument if a provided pair of generic integers are not of the same tag.

OCaml

Innovation. Community. Security.