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 by the S.of_string_exn implementations.

type u8

An unsigned 8-bit integer.

val equal_u8 : u8 -> u8 -> Ppx_deriving_runtime.bool
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 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 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 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 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 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 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 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 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 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 show_generic : generic -> Ppx_deriving_runtime.string
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.

type signedness =
  1. | Unsigned
  2. | Signed

Represents integer signedness.

val equal_signedness : signedness -> signedness -> Ppx_deriving_runtime.bool
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 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 show_int_ty : int_ty -> Ppx_deriving_runtime.string
val all_of_int_ty : int_ty list
module type Singleton = sig ... end

A single integer of an arbitrary type.

module type Pair = sig ... end

A pair of integers of an arbitrary type.

val ops : int_ty -> (module S)

Finds an integer implementation based on its type representation.

val singleton : generic -> (module Singleton)

Constructs an integer singleton.

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.

val generic_int_ty : generic -> int_ty

Determines the type representation of a generic integer.

OCaml

Innovation. Community. Security.