Terence
I wrote Terence, a math library for the Goose language, to have a reason to learn it. It ports the parts of Go's math package I could follow.
- Status
- ○ Research
- Year
- 2026
- Stack
- Goose · IEEE 754 · C shim
- Source
- Nurysso/terence
- 34
- 21
- 6
01 / Overview
What it does
A hobby math library for the Goose programming language, named after Terence Tao. It ports the parts of Go's math package I could get my head around: constants, float bit tricks, rounding, binary ops, decomposition, and sqrt, cbrt and hypot. It aims for Go's behaviour on NaN, ±Inf, signed zero and subnormals, takes plain f64 in and returns plain f64, and is heavily commented. It has not been benchmarked and is not battle-tested.
02 / Usage
Import the directory, call a function
git clone https://github.com/Nurysso/terence.gitimport terence from "path/to/terence"; // the directory, not a file
fn main() {
print("sqrt(9) = ", sqrt(9.0));
print("cbrt(27) = ", cbrt(27.0));
print("hypot(3, 4) = ", hypot(3.0, 4.0));
let whole, frac = modf(3.75);
print("modf(3.75) = ", whole, " + ", frac);
}goose run tests/basic_test.goose
goose run tests/bits_test.goose
goose run tests/float_binary_ops_test.goose
goose run tests/float_decomposition_test.goose03 / Inside
What's here
Constants
E, Pi, Phi, Sqrt2, SqrtE, SqrtPi, SqrtPhi, Ln2, Ln10, Log2E and Log10E, plus the float and int limits such as MaxFloat64 and MaxInt. Works and is tested.
Float bits and basics
float64_bits, float64_frombits, float32_bits, float32_frombits, nan, inf, is_nan, is_inf, signbit, abs, copysign, normalize and exact_pow2. Works and is tested.
Rounding
floor, ceil, round, trunc, round_to_even and modf. Works and is tested.
Binary ops
max, min, dim, mod, remainder and fma. Works and is tested, but fma is not a real fused multiply-add.
Decomposition
frexp, ldexp, ilogb, logb, next_after and next_after32. Works and is tested.
Roots
sqrt, cbrt and hypot. They work on the inputs I tried and have no tests yet.
04 / Goals
What it aims for
Go's edge cases
The same behaviour as the Go math package for NaN, ±Inf, signed zero and subnormals, since Go is the reference.
No heap allocation
Everything is plain f64 in, f64 out. I have not checked with a tool, but nothing in it needs an allocation.
Lots of comments
I write down why the code does what it does, mostly so future me can follow along.
05 / Honesty
What it does not claim
Not high-performance
cbrt is a loop of Newton iterations. It is correct-ish, not fast.
Not pure Goose
sqrt calls a tiny C shim to use the hardware square-root instruction, so building needs a C compiler and libm.
Not bit-identical
Results are not guaranteed to match Go's, or to match across platforms.
06 / Roadmap
On a free weekend
Tests for the roots
Tests for sqrt, cbrt and hypot.
exp and log
exp, exp2, expm1, log, log2, log10 and log1p.
pow
pow and pow10.
Trig and hyperbolic
sin, cos, tan, asin, acos, atan, atan2, sinh, cosh, tanh and friends.
The fancy stuff
gamma, lgamma, the erf family and Bessel functions.
A real fma
And maybe getting rid of the C shim.
07 / Install
Get it running
git clone https://github.com/Nurysso/terence.git08 / Limits
Rough edges
- Early and unfinished. exp, log, pow, trig, gamma and the rest are still empty files.
- fma is not a real fused multiply-add. It computes a*b + c with two roundings.
- sqrt calls a small C shim for the hardware instruction, so building needs a C compiler and libm.
- Results are not guaranteed to match Go's bit for bit, or to match across platforms.
09 / FAQ
Before you try it
- Why Goose?
- I like Go, I like Goose, and math is a well-specified chunk of code to port while working out how a new language feels. That is the whole pitch.
- Why the name?
- It is named after Terence Tao, because I like the name.
- Can I use it for real work?
- Not yet. It is early and unfinished, it has not been benchmarked, and it is not battle-tested.
- Where does the code come from?
- A lot of the logic, tests and comments are ported from Go's math package (BSD-3-Clause, Copyright 2009 The Go Authors), and some of that goes back to FreeBSD's msun and Sun's fdlibm. Terence itself is Apache-2.0, and the original licence texts are in the NOTICE file.
Terence
I wrote Terence, a math library for the Goose language, to have a reason to learn it. It ports the parts of Go's math package I could follow.