#integer #compiler #interpreter #semantics #imp #modeling #thinly-wrapped

nightly imp_int

A collection of thinly-wrapped integer types modelling IMP integer semantics

3 unstable releases

0.3.1 Apr 21, 2024
0.3.0 Apr 20, 2024
0.2.0 Apr 20, 2024

#339 in Programming languages

Download history 359/week @ 2024-04-18 30/week @ 2024-04-25

389 downloads per month
Used in 4 crates

MIT license

15KB
289 lines

imp_int

What is an integer newtype but a miserable pile of macros?

This crate provides the following thinly-wrapped types:

  • u8 => Imp8;
  • u16 => Imp16;
  • u32 => Imp32;
  • u64 => Imp64;
  • u128 => Imp128;
  • usize => ImpSize.

With the bigint feature enabled, it also provides the ImpBigInt type as a wrapper over the num_bigint::BigUint type to provide an arbitrary precision integer with IMP integer semantics.

Installation

# ordinary usage
cargo add imp_int

# usage with the bigint feature enabled
cargo add imp_int --features bigint

lib.rs:

Thinly-wrapped integer types modelling IMP integer semantics.

In a general sense, an IMP integer is just an unsigned integer with addition and multiplication defined in the normal sense, and where subtraction is defined to saturate at 0. However, this is complicated by the fact that IMP does not define integer overflow; it forces implementations to decide how correct they wish to be.

For this reason, the types in this crate implement checked addition and multiplication in both debug and release builds (excluding ImpBigInt, which avoids these checks by being practically unbounded).

Dependencies

~230KB