Module Usane

module Usane: sig .. end
Sane unsigned integers.

Arithmetic operations on unsigned integers of fixed width may overflow. This library exposes the carry bit of arithmetic operations explicitly: The value of each arithmetic operation is a tuple of the (maybe wrapped) value, and the carry bit.

It is designed for network protocols where sequence numbers are used (and either overflows are accepted or should lead to re-establishing or re-keying of the connection). Most protocols only use simple arithmetic operations, such as a comparison and incrementing by one.

To ease interoperation with other libraries, the representation is the same width signed representation provided by OCaml, if present (which is the case for int32 and int64).

The implementation of usane uses C compiler builtins (__builtin_uadd_overflow etc.). These are available since GCC 5.1 and Clang 3.4.

6cd1fe8 - homepage


module Uint8: sig .. end
Unsigned 8 bit integers, ranging from 0 to 2 ^ 8 - 1 (255).
module Uint16: sig .. end
Unsigned 16 bit integers, ranging from 0 to 2 ^ 16 - 1 (65535).
module Uint32: sig .. end
Unsigned 32 bit integers, ranging from 0 to 2 ^ 32 - 1 (4294967295).
module Uint64: sig .. end
Unsigned 64 bit integers, ranging from 0 to 2 ^ 64 - 1 (18446744073709551615).