MathVerse Core
Shared substrate for the MathVerse ecosystem — traits, scalar operations, precision, constants, and algorithms.
Features
- Zero-dependency — runs on
no_std, embedded-friendly - Generic math traits —
Num,Signed,Field,Realwith blanket impls forf32/f64 - 30+ scalar operations — lerp, smoothstep, nth_root, hypot, wrap, angle conversions
- Float precision — ULP comparison, relative/absolute tolerances, safe division
- 50+ math constants — pi, tau, e, phi, sqrt(2), and their reciprocals
- Number theory — GCD, LCM, primes (sieve, Miller-Rabin), factorials, Fibonacci, Bell numbers, Euler phi
- Combinatorics — Catalan, Stirling, partitions, Pascal's triangle, derangements
- Prelude — one-import access to the most-used items
#[must_use]on all pure functions — prevent silent discard bugs#[inline]on trivial leaf functions — optimizer hints for generic code- Comprehensive doc-tests — every public function has runnable examples
- Property-based tests — mathematical invariants verified via
proptest - Benchmarks —
criterionbenchmarks for hot paths
Module Overview
| Module | What it does |
|---|---|
traits |
Core numeric trait hierarchy (Num -> Signed -> Field -> Real) |
ops |
Scalar math operations: lerp, smoothstep, hypot, nth_root, wrap, trig |
precision |
Float comparison: almost_eq, ULP, significant figures, safe division |
constants |
50+ math constants (PI, TAU, E, PHI, SQRT_*, ...) |
algorithms |
GCD, LCM, primes, factorials, Fibonacci, binomial, Catalan, Bell |
error |
MathError enum, MathResult<T> type alias, #[non_exhaustive] |
prelude |
Re-exports of the most commonly used items |
Trait Hierarchy
┌─────────┐
│ Num │ Integer + Float
└────┬────┘
│
┌────────┴────────┐
│ │
┌────┴────┐ ┌─────┴─────┐
│ Signed │ │ Unsigned* │ (*marker, not enforced)
└────┬────┘ └───────────┘
│
┌────────┴────────┐
│ │
┌────┴────┐ ┌──────┴──────┐
│ Field │ │ (marker) │
└────┬────┘ └─────────────┘
│
┌────┴────┐
│ Real │ f32 / f64 blanket impl
└─────────┘
All traits are implemented for f32 and f64 via blanket impls, so generic code works out of the box.
Installation
[]
= { = "../mathverse-core" }
For no_std environments, disable the std feature:
= { = "../mathverse-core", = false }
Quick Start
use *;
Error Handling
use ;
// Access the error message:
let err = DivisionByZero;
assert_eq!;
assert_eq!;
// Convert to String:
let s: String = Overflow.into;
MSRV
The minimum supported Rust version is 1.87.
Roadmap
| Phase | What |
|---|---|
| 0.3.0 | Statistics module (mean, median, variance, correlation) |
| 0.3.0 | Numerical methods (root finding, integration, differentiation) |
| 0.4.0 | Polynomial arithmetic and interpolation |
| 0.4.0 | Special functions (gamma, beta, erf, bessel) |
| 0.5.0 | Complex<T> and Matrix types |
| 0.5.0 | SIMD-accelerated trait impls for f32x4 / f64x2 |
License
MIT — see LICENSE.