1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
//! `puremp` — arbitrary-precision arithmetic written entirely in Rust, depending
//! on no foreign code.
//!
//! It provides a family of numeric types, built bottom-up:
//!
//! 1. **Integers** — unsigned [`Nat`] and signed [`Int`], the workhorse layer
//! that carries the hard limb-level algorithms (multiplication, division,
//! GCD, modular arithmetic, …). Enabled by the `int` feature.
//! 2. **Rationals** — [`Rational`], exact `p/q` fractions kept in lowest terms;
//! plus [`InfRational`], the same extended with `±∞`/`NaN`. `rational` feature.
//! 3. **Dyadics** — [`Dyadic`], exact `n·2^-k` binary fractions. `dyadic` feature.
//! 4. **Floats** — [`Float`], binary floating-point with a caller-chosen
//! precision and directed [`RoundingMode`], aiming at MPFR-class correct
//! rounding, plus [`FixedFloat`], a fixed-precision wrapper with operators.
//! `float` feature.
//! 5. **Decimals** — [`Decimal`], exact base-10 floating point (Python
//! `Decimal`-style), with directed rounding. `decimal` feature.
//!
//! Built on top of these are several *derived* structures, each generic or
//! specialised as noted:
//!
//! - [`ModInt`] — modular integers `ℤ/mℤ` with automatic reduction (`int`).
//! - [`Complex`] — generic complex numbers / Gaussian integers (`complex`).
//! - [`Poly`] — generic univariate polynomials (`poly`).
//! - [`Matrix`] — dense matrices with exact determinant/inverse/solve
//! (`matrix`).
//! - [`Interval`] — outward-rounded interval arithmetic (`interval`).
//! - [`Quadratic`] / [`Algebraic`] — exact quadratic irrationals `ℚ(√d)` and
//! general real algebraic numbers (`algebraic`).
//!
//! `Int`/`Rational` also carry a number-theory toolkit (factorization,
//! `sqrt_mod`, Jacobi/Legendre, CRT, `random_prime`, combinatorics,
//! continued-fraction approximation), and an optional `num-traits` bridge slots
//! the types into generic numeric code.
//!
//! `puremp` is usable as a Rust library, a C library (the `ffi` feature; see
//! `include/puremp.h`), and a standalone command-line calculator (the `cli`
//! feature; the `puremp` binary).
//!
//! This is a clean-room implementation: it is MIT-licensed and its algorithms
//! are drawn from the open literature, never from GMP/MPFR source. See
//! `ROADMAP.md` for the design, the algorithm references, and the milestone
//! plan.
//!
//! # Example
//!
//! ```
//! use puremp::{Int, Rational};
//!
//! // Arbitrary-precision integers.
//! let big = Int::from(2).pow(128);
//! assert_eq!(big.to_string(), "340282366920938463463374607431768211456");
//! assert_eq!(Int::from(1071).gcd(&Int::from(462)).to_string(), "21");
//! assert_eq!(Int::from(2).modpow(&Int::from(10), &Int::from(1000)).to_string(), "24");
//!
//! // Exact rationals, always in lowest terms.
//! let third = Rational::new(Int::from(1), Int::from(3));
//! let sum = &(&third + &third) + &third;
//! assert_eq!(sum.to_string(), "1");
//! ```
//!
//! # `no_std`
//!
//! The crate is `#![no_std]` at its core. Arbitrary-precision types are
//! heap-backed, so they need the `alloc` crate; the `alloc` feature (implied by
//! every type layer) pulls it in. The `std` feature (enabled by default) adds
//! the pieces that genuinely need the operating system — the CLI, `std::error`
//! integration, and system I/O. Build with `--no-default-features` for a bare
//! `no_std` target.
extern crate alloc;
extern crate std;
pub use ;
pub use ;
pub use ;
pub use RandomSource;
pub use InfRational;
pub use Rational;
pub use ModInt;
pub use Dyadic;
pub use ;
pub use Complex;
pub use Poly;
pub use Matrix;
pub use Algebraic;
pub use Quadratic;
pub use FixedFloat;
pub use ;
pub use Interval;
/// The crate version string (`CARGO_PKG_VERSION`), exposed for the C ABI and CLI.
pub const VERSION: &str = env!;