Documentation
¶
Overview ¶
Package fastmath provides faster float32 approximations of selected math functions for use in go-backend kernels where small errors are acceptable (e.g. softmax, activations).
Not for paths that need standard-library accuracy or special-value behavior (Inf, NaN, subnormals). Use math.* there instead.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Exp32 ¶
Exp32 approximates e^x for float32.
Algorithm (Cephes-style expf, Stephen L. Moshier):
- Clamp x to ≈ [-127 ln 2, 127 ln 2].
- Reduce: x = n·ln2 + g with |g| ≤ ln2/2, n = round(x / ln2). ln2 is split (hi/lo) so n·ln2 is subtracted accurately.
- Approximate e^g with a degree-7 Horner polynomial (Cephes).
- Scale by exact 2^n via the float32 exponent field: bits (n+127)<<23.
Accuracy vs math.Exp: max relative error < 1e-7 over the normal float32 range (see TestExp32). Not bit-identical to math.Exp; overflow/underflow return a large finite / 0 rather than ±Inf / subnormals.
Intended for go-backend fused ops (softmax, etc.) where math.Exp on float32 dominates runtime and this precision is enough. Softmax always evaluates exp(x-max) ≤ 1, so arguments are ≤ 0 and the overflow clamp is unused.
Types ¶
This section is empty.