[ANN] checked_oint v0.5.0: Safe integer arithmetic for OCaml

I would like to announce checked_oint v0.5.0, which provides checked integer arithmetic for OCaml. We support both signed and unsigned integers of 8, 16, 32, 64, and 128 bits. Unlike other libraries, checked_oint either returns an option or raises an exception when the result of an arithmetic operation cannot be represented in a desired integer type.

In addition, it contains abstractions for manipulating arbitrary integers and integer types in a generic and type-safe manner, which I find tremendously useful for compiler/interpreter implementations.

Usage example:

open Checked_oint

let () =
  let x = U8.of_int_exn 50 in
  let y = U8.of_int_exn 70 in
  assert (U8.equal (U8.add_exn x y) (U8.of_int_exn 120));
  assert (Option.is_none (U8.mul x y))

The release v0.5.0 introduced crucial functionality for converting between any two integer types in a safe manner – see S.of_generic and S.of_generic_exn.

2 Likes