# \[ANN\] checked\_oint v0.5.0: Safe integer arithmetic for OCaml

**URL:** <https://discuss.ocaml.org/t/ann-checked-oint-v0-5-0-safe-integer-arithmetic-for-ocaml/16450>\
**Category:** Community\
**Tags:** announce\
**Created:** [April 7, 2025, 4:14pm UTC](https://discuss.ocaml.org/t/ann-checked-oint-v0-5-0-safe-integer-arithmetic-for-ocaml/16450 "2025-04-07T16:14:44Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hirrolot](https://sea2.discourse-cdn.com/flex020/user_avatar/discuss.ocaml.org/hirrolot/32/4100_2.png) [@Hirrolot](https://discuss.ocaml.org/u/Hirrolot)\
**Post date:** [April 7, 2025, 4:14pm UTC](https://discuss.ocaml.org/t/ann-checked-oint-v0-5-0-safe-integer-arithmetic-for-ocaml/16450/1 "2025-04-07T16:14:44Z")

</div>

I would like to announce [`checked_oint`](https://github.com/hirrolot/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:

```ocaml
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`](https://hirrolot.github.io/checked_oint/checked_oint/Checked_oint/module-type-S/index.html#val-of_generic) and [`S.of_generic_exn`](https://hirrolot.github.io/checked_oint/checked_oint/Checked_oint/module-type-S/index.html#val-of_generic_exn).
