package checked_oint

  1. Overview
  2. Docs

Module Checked_ointSource

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.

Sourceexception Out_of_range

The exception raised on underflows/overflows.

Sourcetype u8

An unsigned 8-bit integer.

Sourceval compare_u8 : u8 -> u8 -> Ppx_deriving_runtime.int
Sourcetype u16

An unsigned 16-bit integer.

Sourceval compare_u16 : u16 -> u16 -> Ppx_deriving_runtime.int
Sourcetype u32

An unsigned 32-bit integer.

Sourceval compare_u32 : u32 -> u32 -> Ppx_deriving_runtime.int
Sourcetype u64

An unsigned 64-bit integer.

Sourceval compare_u64 : u64 -> u64 -> Ppx_deriving_runtime.int
Sourcetype u128

An unsigned 128-bit integer.

Sourceval compare_u128 : u128 -> u128 -> Ppx_deriving_runtime.int
Sourcetype i8

A signed 8-bit integer.

Sourceval compare_i8 : i8 -> i8 -> Ppx_deriving_runtime.int
Sourcetype i16

A signed 16-bit integer.

Sourceval compare_i16 : i16 -> i16 -> Ppx_deriving_runtime.int
Sourcetype i32

A signed 32-bit integer.

Sourceval compare_i32 : i32 -> i32 -> Ppx_deriving_runtime.int
Sourcetype i64

A signed 64-bit integer.

Sourceval compare_i64 : i64 -> i64 -> Ppx_deriving_runtime.int
Sourcetype i128

A signed 128-bit integer.

Sourceval compare_i128 : i128 -> i128 -> Ppx_deriving_runtime.int
Sourcetype 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.

Sourcetype signedness =
  1. | Unsigned
  2. | Signed

Represents integer signedness.

Sourceval all_of_signedness : signedness list
Sourcetype bitness =
  1. | Bits8
  2. | Bits16
  3. | Bits32
  4. | Bits64
  5. | Bits128

Represents integer bitness.

Sourceval all_of_bitness : bitness list
Sourcetype int_ty = signedness * bitness

Represents an integer type.

Sourceval all_of_int_ty : int_ty list
include sig ... end
Sourceval u8_int_ty : int_ty
Sourceval u16_int_ty : int_ty
Sourceval u32_int_ty : int_ty
Sourceval u64_int_ty : int_ty
Sourceval u128_int_ty : int_ty
Sourceval i8_int_ty : int_ty
Sourceval i16_int_ty : int_ty
Sourceval i32_int_ty : int_ty
Sourceval i64_int_ty : int_ty
Sourceval i128_int_ty : int_ty
Sourceval generic_int_ty : generic -> int_ty

Determines the type representation of a generic integer.

Sourceval is_zero : generic -> bool

true if the integer is 0, false otherwise.

Sourceval is_one : generic -> bool

true if the integer is 1, false otherwise.

Sourceval is_all_ones : generic -> bool

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

Sourcemodule type S = sig ... end

The signature of operations on integers.

Sourcemodule U8 : S with type t = u8

The implementation of u8.

Sourcemodule U16 : S with type t = u16

The implementation of u16.

Sourcemodule U32 : S with type t = u32

The implementation of u32.

Sourcemodule U64 : S with type t = u64

The implementation of u64.

Sourcemodule U128 : sig ... end

The implementation of u128.

Sourcemodule I8 : S with type t = i8

The implementation of i8.

Sourcemodule I16 : S with type t = i16

The implementation of i16.

Sourcemodule I32 : S with type t = i32

The implementation of i32.

Sourcemodule I64 : S with type t = i64

The implementation of i64.

Sourcemodule I128 : sig ... end

The implementation of i128.

Sourceval ops : int_ty -> (module S)

Finds an integer implementation based on its type representation.

Sourcemodule type Singleton = sig ... end

A single integer of an arbitrary type.

Sourceval singleton : generic -> (module Singleton)

Constructs an integer singleton.

Sourcemodule type Pair = sig ... end

A pair of integers of an arbitrary type.

Sourceval pair : (generic * generic) -> (module Pair) option

Constructs a pair of integers; returns None if a provided pair of generic integers are not of the same tag.

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

Same as pair but raises Invalid_argument instead of returning None.

OCaml

Innovation. Community. Security.