gMath

g_math

Pure-Rust, zero-float, deterministic multi-domain fixed-point arithmetic.

Built by Niels Erik Toren · published as g_math on crates.io


Upgrading from 0.4.x? 0.5.0 is more accurate, and as a side effect some results end in a different final digit. It matters only if you store, hash, or compare results across versions. The four-line summary is at the top of CHANGELOG.md.

0.6.0 adds certified arithmetic (Interval, DecimalInterval), a proven positive-definiteness verdict (pd_verdict) and exact geometric predicates, all additive. 0.5.1 carries only the three defect fixes that work found in 0.5.0 (two on the scientific profile, one in the wide decimal integers); every ^0.5 user receives them without adopting any new API.


What it is

g_math computes with scaled integers only. No f32/f64 appears anywhere in the arithmetic, validation, or comparison paths (float conversions exist solely as caller-convenience from_f64/to_f64 wrappers). Because every operation is integer arithmetic, results are bit-identical on every architecture - which makes the crate suitable for blockchain consensus, financial auditing, and reproducible scientific computation.

It is a library, not a service: pure computation, no I/O, no ambient state. Values route across four numeric domains (binary, decimal, balanced ternary, symbolic rational), and 18 transcendental functions plus linear algebra, geometry, and ternary-quantized inference are built on top. It is one component of the Geodineum ecosystem and is consumed by its geometric and inference projects.

Public build surface

The build-with surface is five layers; everything beneath them is internal.

The complete per-symbol index - every public item and a one-line summary - is generated from source into PUBLIC_API.md (rustc -O scripts/gen-public-api.rs -o /tmp/gen-public-api && /tmp/gen-public-api). Live signatures are on docs.rs. This README never re-hosts either.

Guides

Each layer and cross-cutting concept has a focused guide under docs/.

Guide What it covers
Routing (FASC) The gmath()/evaluate() layer: lazy trees, cross-domain routing, chain persistence (tier N+1), UGOD graceful overflow, the shadow system, mode routing
Imperative FixedPoint/FixedVector/FixedMatrix + DecimalFixed: direct, no-routing, Copy types for hot loops
Transcendentals The 18 functions: dedicated engines, composed forms, fused sincos/sinhcosh, try_* variants
Fused operations Compute-tier sqrt_sum_sq, euclidean_distance, softmax, softmax_mix, rms_norm_factor, silu
Linear algebra LU/QR/Cholesky/SVD/eigen/Schur, solvers, matrix functions
Geometry Manifolds, Lie groups, curvature, projective geometry, fiber bundles, ODE, tensors
Ternary & TQ1.9 Balanced-ternary arithmetic and the trit-plane inference weight formats
Precision & profiles The five profiles, GMATH_FRAC_BITS, rounding, validation, feature flags, build

Capabilities

Contract

The precise contract - the supported surface and its stability boundary, the determinism guarantee, the per-domain rounding rules, cross-profile semantics, and what the crate requires - is in CONTRACT.md. Agents should prime from CONTRACT.scn.md.

Quick start

cargo add g_math
use g_math::canonical::{gmath, evaluate};

// "100" and "50" route to binary, "3" keeps the result exact via symbolic routing.
let value = evaluate(&((gmath("100") + gmath("50")) / gmath("3"))).unwrap();
println!("{value}");

From here, follow the guides: the routing guide for mixed-domain and chained work, or the imperative guide for direct hot-loop arithmetic.

Limits worth knowing

Collaborate

Contributions are welcome. Open issues and pick up work on the ecosystem board at geodineum.com; issues tagged good-first-issue are a good place to start.

Author & support

Built by Niels Erik Toren.

If you want to support the work:

Currency Address
Bitcoin (BTC) bc1qwf78fjgapt2gcts4mwf3gnfkclvqgtlg4gpu4d
Ethereum (ETH) 0xf38b517Dd2005d93E0BDc1e9807665074c5eC731 / nierto.eth
Monero (XMR) 8BPaSoq1pEJH4LgbGNQ92kFJA3oi2frE4igHvdP9Lz2giwhFo2VnNvGT8XABYasjtoVY2Qb3LVHv6CP3qwcJ8UnyRtjWRZ5

Disclaimer

This software is provided "as is", without warranty of any kind, express or implied. Use of this software is entirely at your own risk. In no event shall the author or contributors be held liable for any damages arising from the use or inability to use this software.

"Certified" is a technical term, not a warranty. Where this documentation says certified, proven or enclosure, it means exactly what CONTRACT.md §3 and docs/design/CERTIFIED_INTERVALS.md define: a statement about the exact integer computation performed on the values passed in, established by construction and gated by tests. It is not a warranty of fitness for any purpose, and the paragraph above applies to it in full.

License

Licensed under either of

at your option.