fastmath

package
v0.1.21 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 2, 2026 License: Apache-2.0 Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

func Exp32(x float32) float32

Exp32 approximates e^x for float32.

Algorithm (Cephes-style expf, Stephen L. Moshier):

  1. Clamp x to ≈ [-127 ln 2, 127 ln 2].
  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.
  3. Approximate e^g with a degree-7 Horner polynomial (Cephes).
  4. 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL