[][src]Crate modtype

This crate provides modular arithmetic integer types.

Usage

modtype::ModType

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

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

modtype::thread_local::ModType

#[allow(non_snake_case)]
modtype::thread_local::DefaultModType::with(57u32, |Z| {
    assert_eq!(Z(42) + Z(15), Z(0));
});

modtype::field_param::ModType

use num::CheckedDiv as _;

#[allow(non_snake_case)]
let Z = modtype::field_param::DefaultModType::factory(1000u32);

assert_eq!(Z(1).checked_div(&Z(777)), Some(Z(713))); // 777 × 713 ≡ 1 (mod 1000)

Customization

ModTypes can be customized via modtype::Cartridge.

#[modtype::use_modtype]
type F = modtype::ModType<u64, Cartridge, 1_000_000_007u64>;

enum Cartridge {}

impl modtype::Cartridge for Cartridge {
    type Target = u64;
    type Features = modtype::DefaultFeatures;

    // your implementation here
}

Re-exports

pub use modtype_derive::use_modtype;
pub use modtype_derive::ConstValue;
pub use modtype_derive::ModType;

Modules

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.

Structs

ModType

A modular arithmetic integer type which modulus is a constant.

Enums

DefaultCartridge

The default implementation.

DefaultFeatures

The default features.

False

A TypedBool which represents "false".

NonPrime

The implementation for non prime moduluses.

True

A TypedBool which represents "true".

Traits

Cartridge

Actual implementation.

ConstValue

A trait that has one associated constant value.

Features

Features.

FloatPrimitive

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

SignedPrimitive

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

TypedBool

Type level boolean.

UnsignedPrimitive

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

Type Definitions

DefaultModType

A type alias which Cartridge is DefaultCartridge<M::Value>.