[][src]Crate modtype

This crate provides modular arithmetic integer types.

Usage

modtype::Z

#[modtype::use_modtype]
type F = modtype::u64::Z<1_000_000_007u64>;

assert_eq!((F(1_000_000_006) + F(2)).to_string(), "1");

modtype::thread_local::Z

#[allow(non_snake_case)]
modtype::thread_local::u32::Z::with(7, |F| {
    assert_eq!(F(6) + F(1), F(0));
});

modtype::field_param::Z

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

#[allow(non_snake_case)]
let Z = Z::factory(1000);

assert_eq!(Z(1).checked_div(&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<u64, Impl, 1_000_000_007u64>;

enum Impl {}

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

    // your implementation here
}

Attributes for use_modtype

NameFormatOptional
constantconstant($Ident)Yes (default = concat!(_, $value, $type_uppercase))
constructorconstructor($Ident)Yes (default = the type alias)

Re-exports

pub use modtype_derive::use_modtype;

Modules

derive

Derive macros.

field_param

A modular arithmetic integer type which modulus is a struct field.

thread_local

A modular arithmetic integer type which modulus is thread_local.

u8

A type alias.

u16

A type alias.

u32

A type alias.

u64

A type alias.

u128

A type alias.

usize

A type alias.

Structs

Z

A modular arithmetic integer type which modulus is a constant.

Enums

DefaultImpl

The default implementation.

Traits

ConstValue

A trait that has one associated constant value.

FloatPrimitive

A trait for primitive floating point number type. (i.e. f32, f64)

Impl

Actual implementation.

SignedPrimitive

A trait for primitive signed integer types. (i.e. i8, i16, i32, i64, i128, isize)

UnsignedPrimitive

A trait for primitive unsigned integer types. (i.e. u8, u16, u32, u64, u128, usize)