Skip to main content

relp_num/
lib.rs

1//! # relp-num
2//!
3//! Number types for the [RELP](https://crates.io/crates/relp) crate.
4#![warn(missing_docs)]
5// The tests deliberately exercise the operator impls in ways clippy reads as mistakes: calling the
6// by-reference impls (`op_ref`), asserting the exact boolean a comparison yields on `Sign`, which
7// is a genuinely partial order (`bool_assert_comparison`), using `x = x + y` to test `Add` rather
8// than `AddAssign` (`assign_op_pattern`), and multiplying by zero (`erasing_op`).
9#![cfg_attr(test, allow(
10    clippy::op_ref,
11    clippy::bool_assert_comparison,
12    clippy::assign_op_pattern,
13    clippy::erasing_op,
14))]
15
16mod binary;
17mod zero;
18mod one;
19mod signed_one;
20
21/// Number types whose value is fixed at compile time.
22///
23/// A matrix provider often stores coefficients that can only take one or two values: the incidence
24/// matrix of a network is nothing but `1`, `-1` and `0`. Storing such a coefficient in a rational
25/// number wastes both space and time, so these types store it in no space at all and let
26/// [`Absorb`] apply it to a wide accumulator directly.
27///
28/// They live in their own module because [`One`](one::One) and [`Zero`](zero::Zero) would otherwise shadow the
29/// `num_traits` traits of the same name, which are in scope in most code that uses this crate.
30pub mod fixed {
31    pub use crate::binary::Binary;
32    pub use crate::one::One;
33    pub use crate::signed_one::SignedOne;
34    pub use crate::zero::Zero;
35}
36
37mod integer;
38pub use integer::factorization::prime::Prime;
39pub use integer::big::Ubig;
40pub use integer::big::NonZeroUbig;
41
42mod non_zero;
43pub use non_zero::NonZero;
44pub use non_zero::sign::NonZeroSign;
45pub use non_zero::sign::NonZeroSigned;
46
47mod rational;
48// The inline capacity is part of the type, and a crate that implements `Absorb` for its own narrow
49// type has to name the wide type it implements it for. Exporting only the alias for capacity eight
50// would limit such an implementation to that one capacity.
51pub use rational::big::Big;
52pub use rational::big::NonZeroBig;
53pub use rational::RationalBig;
54pub use rational::RationalUsize;
55pub use rational::Rational128;
56pub use rational::Rational64;
57pub use rational::Rational32;
58pub use rational::Rational16;
59pub use rational::Rational8;
60pub use rational::NonZeroRationalBig;
61pub use rational::NonZeroRationalUsize;
62pub use rational::NonZeroRational128;
63pub use rational::NonZeroRational64;
64pub use rational::NonZeroRational32;
65pub use rational::NonZeroRational16;
66pub use rational::NonZeroRational8;
67
68mod sign;
69pub use sign::Sign;
70pub use sign::Signed;
71pub use sign::Negateable;
72
73mod traits;
74pub use traits::Abs;
75pub use traits::Absorb;
76pub use traits::AbsorbAll;
77pub use traits::factorization::NonZeroFactorizable;
78pub use traits::factorization::NonZeroFactorization;
79pub use traits::factorization::FactorizationResidual;
80pub use traits::Field;
81pub use traits::FieldRef;
82pub use traits::OrderedField;
83pub use traits::OrderedFieldRef;
84
85// This re-export is used in macros used to construct rationals in tests.
86pub use num_traits::FromPrimitive;