Transcendentals
18 functions, available on LazyExpr, FixedPoint, and DecimalFixed, each
computed at tier N+1 (one width above storage) with a single downscale at the end.
What it is
The transcendental engines are the numerical core. Six are dedicated
algorithms (table-driven or Newton-Raphson); the remaining twelve are composed
from those six but still evaluated entirely at the wide compute tier, so a
composition rounds once rather than accumulating a rounding per step. The same 18
functions are reachable three ways: lazily via
gmath(...), directly on
FixedPoint, and natively on
DecimalFixed.
Usage
use g_math::fixed_point::FixedPoint;
let x = FixedPoint::from_str("1.5");
let a = x.exp();
let (s, c) = x.sincos(); // fused: sin and cos from one range reduction
let (sh, ch) = x.sinhcosh(); // fused: sinh and cosh from one exp pair
// Fallible variants surface overflow instead of saturating.
let r = x.try_exp(); // Result<FixedPoint, OverflowDetected>
// Shared range reduction through the canonical layer, too.
use g_math::canonical::{gmath, evaluate_sincos};
let (s, c) = evaluate_sincos(&gmath("0.7")).unwrap();
The 18 functions
Dedicated engines (table-driven or Newton-Raphson, at tier N+1):
| Function | Algorithm |
|---|---|
exp |
integer part by squaring + 3-stage table lookup + Taylor remainder |
ln |
multiplicative decomposition, 3-stage tables + Taylor |
sqrt |
integer Newton-Raphson |
sin, cos |
Cody-Waite range reduction + Horner Taylor (sincos fuses both) |
atan, atan2 |
3-level argument reduction + Taylor |
Composed from the dedicated engines, still at the wide tier:
| Function | Composition |
|---|---|
tan |
sin / cos |
pow(x, y) |
exp(y·ln x) |
asin, acos |
atan(x/√(1−x²)), π/2 − asin |
sinh, cosh |
(eˣ ∓ e⁻ˣ)/2 (sinhcosh fuses both on one exp pair) |
tanh |
(e²ˣ−1)/(e²ˣ+1) |
asinh, acosh, atanh |
log forms |
Public API
Transcendental methods appear on each surface's entry in the index:
FixedPoint,
DecimalFixed, and the canonical
LazyExpr methods. Fused pairs are
sincos/sinhcosh (imperative) and evaluate_sincos/evaluate_sinhcosh
(canonical). Live signatures on docs.rs.
With the inference feature, g_math::compute_tier
exposes the tier-N+1 engines directly over raw ComputeStorage values at
2·FRAC_BITS precision (exp/ln/sqrt/sinhcosh plus sigmoid/softplus/ln1p
compositions) for wide-precision consumers (e.g. chaining on the wide-output
matvec_q2f accumulators without an intermediate storage rounding). Results are
path-independent with the surfaces above: to_fixed(compute_tier::exp(from_fixed(x)))
is bit-identical to x.exp().
Behaviour & limits
- On
FixedPoint, every function also has a fallibletry_*variant returningResult<_, OverflowDetected>. - On
DecimalFixed, transcendentals run natively in the decimal domain, no round-trip through binary. - Accuracy is defined by the test suite against mpmath references, not by slogans;
see the precision guide and the validation methodology in
CONTRACT.md. Inputs that are inexact in a pinned
representation (e.g.
0.3forced into binary) carry representation error into the result regardless of the engine's accuracy; the canonical router routes such literals to an exact domain automatically, andDecimalFixedcomputes decimals natively at 0 ULP.
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.
Built by Niels Erik Toren · support & donations.