[−][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
ModType
s 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 |
thread_local | A modular arithmetic integer type which modulus is |
Structs
ModType | A modular arithmetic integer type which modulus is a constant. |
Enums
DefaultCartridge | The default implementation. |
DefaultFeatures | The default features. |
False | A |
NonPrime | The implementation for non prime moduluses. |
True | A |
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. |
SignedPrimitive | A trait for primitive signed integer types. (i.e. |
TypedBool | Type level boolean. |
UnsignedPrimitive | A trait for primitive unsigned integer types. (i.e. |
Type Definitions
DefaultModType | A type alias which |