LICENSE=BSD-3-ClauseCGO_ENABLED=0go-bignum is the arbitrary-precision layer for Go: correctly rounded elementary functions and constants on math/big.Float, at any precision and in all six rounding modes, and the oracle harness that drives mpmath from Go to check them. Each function returns the exact result rounded, and says on which side of it the value lies. No cgo, no dependencies.
import "github.com/go-bignum/bigfloat"
z := new(big.Float).SetPrec(113).SetMode(big.ToNearestEven)
bigfloat.Exp(z, x) // e^x, correctly rounded to 113 bits
z.Acc() // big.Below / big.Exact / big.Above:
// the side of the exact valueEvery function returns the exact result rounded to the receiver's precision in the receiver's rounding mode, so results are reproducible bit for bit on every architecture and every Go version. The conventions are math/big's.
Sqrt, Cbrt, Root(z, x, n) and Hypot, correctly rounded in every mode, which big.Float.Sqrt alone is not.
Exp, Expm1, Log, Log1p, Log2, Log10 and Pow.
The six trigonometric functions and their inverses, and the six hyperbolic ones; argument reduction is exact for any argument.
Pi, E, Ln2, Ln10 and EulerGamma, at any precision.
Every approximation is an enclosure (midpoint-radius balls, fixed-point series with bounded error), evaluated by Ziv's strategy: raise the working precision until the enclosure rounds to a single value.
The oracle package drives mpmath from Go, or uses bigfloat itself as the reference, and stores correctly rounded results as golden fixtures other packages can check against.
No cgo, no dependencies. Trigonometric arguments, the Ziv loop and exact roots and powers are bounded, so untrusted input cannot run a function unbounded.
Every repository of the organization. mpmath is an oracle only; MPFR was a reference for the contract, not for code.
The fixtures are generated by go run ./cmd/oracle: Go draws the arguments, drives mpmath at a precision well above the target, and certifies each rounding. They are committed and compared in the tests.
28 840 cases over the 29 functions and constants, at 24, 53, 64, 113, 200 and 1000 bits, each checked in all six rounding modes, value, sign of zero and accuracy: 173 040 results, all identical to the certified roundings. (bigfloat)
FuzzFunctions compares every function, mode and precision with the oracle at more than twice the precision; only ErrNaN and ErrLimit may panic. (bigfloat)
100% statement coverage with -race, and the fixtures on amd64, arm64, 386, arm, riscv64, loong64, ppc64le and s390x in CI. (bigfloat)
Released v0.1.0; every function is at or below mpmath's time on one core (0.18โ0.97ร at 53โ200 bits, 0.27โ0.92ร at 1000 bits; docs/perf.md). Correctly rounded roots, exponentials and logarithms, trigonometric and hyperbolic functions, Pow and the constants ฯ, e, ln 2, ln 10 and ฮณ on math/big.Float, at any precision and in all six rounding modes; the oracle package drives mpmath from Go for correctly rounded reference values and golden fixtures.
The documentation (Hugo + Hextra): one section per library, made of its own README. Source โ
Logos and icons for the organization, in SVG / PNG / JPG / ICO / ICNS across colour, white and black variants.
bigfloat is released v0.1.0, and every function is at or below mpmath's time on one core (docs/perf.md). Its README and design document say what it provides. The documentation is made from them.
Read the source on GitHub โ