modtype

Build Status codecov Crates.io

This crate provides modular arithmetic integer types.

Usage

[modtype::Z]

```

[modtype::use_modtype]

type F = modtype::u64::Z<1_000_000_007u64>;

asserteq!((F(1000000006) + F(2)).to_string(), "1"); ```

[modtype::thread_local::Z]

```

[allow(nonsnakecase)]

modtype::threadlocal::u32::Z::with(7, |F| { asserteq!(F(6) + F(1), F(0)); }); ```

[modtype::field_param::Z]

``` use modtype::field_param::u32::Z; use num::CheckedDiv as _;

[allow(nonsnakecase)]

let Z = Z::factory(1000);

asserteq!(Z(1).checkeddiv(&Z(777)), Some(Z(713))); // 777 × 713 ≡ 1 (mod 1000) ```

Customization

Zs can be customized via [modtype::Impl].

```

[modtype::use_modtype]

type F = modtype::Z;

enum Impl {}

impl modtype::Impl for Impl { type Uint = u64;

// your implementation here

} ```

Attributes for use_modtype

| Name | Format | Optional | | :------------ | :----------------------------- | :---------------------------------------------------- | | constant | constant($[Ident]) | Yes (default = concat!(_, $value, $type_uppercase)) | | constructor | constructor($[Ident]) | Yes (default = the type alias) |