Fork me on GitHub

Arbitrary precision, in pure Go.
Correctly rounded, then checked against an oracle.

go-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.

173 100 certified results, all identical6 rounding modes100% statement coverage
main.go
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 value
3 repositories โ€” one library, released v0.1.0: go get github.com/go-bignum/bigfloat@v0.1.0
Why go-bignum

The MPFR contract, on math/big.

Every 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.

โˆš

Roots

Sqrt, Cbrt, Root(z, x, n) and Hypot, correctly rounded in every mode, which big.Float.Sqrt alone is not.

e

Exponentials and logarithms

Exp, Expm1, Log, Log1p, Log2, Log10 and Pow.

ฯ€

Trigonometric and hyperbolic

The six trigonometric functions and their inverses, and the six hyperbolic ones; argument reduction is exact for any argument.

ฮณ

Constants

Pi, E, Ln2, Ln10 and EulerGamma, at any precision.

๐ŸŽฏ

Rigorous by construction

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.

๐Ÿงช

An oracle for the fleet

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.

๐Ÿ“ฆ

Pure Go, CGO=0

No cgo, no dependencies. Trigonometric arguments, the Ziv loop and exact roots and powers are bounded, so untrusted input cannot run a function unbounded.

โš–๏ธ

BSD-3-Clause

Every repository of the organization. mpmath is an oracle only; MPFR was a reference for the contract, not for code.

What is checked

3 kinds of check, each against a certified answer.

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.

Golden fixtures from mpmath

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)

Fuzzing

FuzzFunctions compares every function, mode and precision with the oracle at more than twice the precision; only ErrNaN and ErrLimit may panic. (bigfloat)

Coverage and architectures

100% statement coverage with -race, and the fixtures on amd64, arm64, 386, arm, riscv64, loong64, ppc64le and s390x in CI. (bigfloat)

Repositories

What is here.

bigfloat

released v0.1.0

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.

docs

site

The documentation (Hugo + Hextra): one section per library, made of its own README. Source โ†’

brand

assets

Logos and icons for the organization, in SVG / PNG / JPG / ICO / ICNS across colour, white and black variants.

Arbitrary precision for Go.

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 โ†’