OneMath is a deterministic .NET math library with correctly rounded elementary functions (such as exp, log, pow, and sin), licensed MIT or Apache-2.0. NuGet · GitHub · Docs
dotnet add package RecursiveAI.OneMath --version 1.0.0
using RecursiveAI.OneMath; var value = Math64.Exp2(-1075); var bits = BitConverter.DoubleToUInt64Bits(value); Console.WriteLine($"0x{bits:X16}");
0x0000000000000000For the same inputs, output format, and rounding mode, correct rounding fixes the bits of a numerical result; determinism alone doesn’t imply accuracy.
Repeatability doesn’t establish accuracy
A function can return the same approximation on every run and still be one representable value away from the right answer. Determinism asks whether the output repeats under the stated conditions. Correct rounding asks which result you get: take the exact mathematical value for the actual floating-point inputs and round it once to the target format under the specified rounding mode, usually round-to-nearest, ties-to-even. That isn’t necessarily the same as rounding a calculation that started with ideal decimal inputs, or rounding each step of an expression.
For OneMath 1.0.0, the elementary-function contract specifies this rounding for Math64 (double) and Math32 (float), with gradual underflow (tiny results can round to subnormal numbers, small nonzero values below the normal range, instead of going straight to zero) and overflow to infinity.
OneMath promises the same output bits for the same inputs across operating systems, CPUs, runtimes, WebAssembly modes, and thread counts, and no 1.x minor or patch release changes an existing result.
Microsoft’s .NET 10 docs for System.Math.Sin and System.Math.Exp do not promise correct rounding for those methods. Both call the underlying C runtime, and Microsoft says the exact result may differ by operating system or architecture.
What ties-to-even means
If an exact result is halfway between adjacent floating-point values, pick the one whose least significant bit of the significand (the last binary digit of the number’s precision) is zero. “Even” refers to that bit, not whether the number is an even integer. For example, Math64.Exp2(-1075) computes 2−1075, exactly halfway between zero and the smallest positive double (2−1074). Zero wins. At −1074 the result is that smallest positive value itself, so it stays nonzero. The pinned tests check the double boundary and the analogous float tie at −150.
Domain errors and canonical NaN
Correct rounding doesn’t give you a real logarithm for a negative number. OneMath’s special-value rules say that a domain error returns NaN, not an exception. When the result is a NaN, OneMath returns the canonical double.NaN or float.NaN rather than preserving a payload-bearing NaN (a NaN with extra bits that can carry information). A NaN input doesn’t always mean a NaN output: the documented Pow(x, ±0) rule returns one even when x is NaN.
Check the results by their bits
Run this program in a .NET 10 console project with RecursiveAI.OneMath 1.0.0. Hex output distinguishes a rounded zero from the smallest subnormal and shows that the domain error and the payload-bearing NaN yield the same bits. This is the output from Linux x64; the run checks these inputs, not the full cross-platform contract.
dotnet new console dotnet add package RecursiveAI.OneMath --version 1.0.0
using RecursiveAI.OneMath; static void Check64(string label, double result, ulong expected) { ulong bits = BitConverter.DoubleToUInt64Bits(result); if (bits != expected) throw new InvalidOperationException(label); Console.WriteLine($"{label}: 0x{bits:X16}"); } static void Check32(string label, float result, uint expected) { uint bits = BitConverter.SingleToUInt32Bits(result); if (bits != expected) throw new InvalidOperationException(label); Console.WriteLine($"{label}: 0x{bits:X8}"); } Check64("Exp2(-1074)", Math64.Exp2(-1074), 1); Check64("Exp2(-1075)", Math64.Exp2(-1075), 0); Check32("Exp2(-149f)", Math32.Exp2(-149), 1); Check32("Exp2(-150f)", Math32.Exp2(-150), 0); ulong nan = BitConverter.DoubleToUInt64Bits(double.NaN); double payload = BitConverter.UInt64BitsToDouble(0x7FF8_0000_0000_0042); Check64("Log(-1)", Math64.Log(-1), nan); Check64("Log(payload NaN)", Math64.Log(payload), nan); Check64("Pow(payload NaN, 0)", Math64.Pow(payload, 0), 0x3FF0_0000_0000_0000);
Exp2(-1074): 0x0000000000000001 Exp2(-1075): 0x0000000000000000 Exp2(-149f): 0x00000001 Exp2(-150f): 0x00000000 Log(-1): 0xFFF8000000000000 Log(payload NaN): 0xFFF8000000000000 Pow(payload NaN, 0): 0x3FF0000000000000
Which guarantee to look for
For a replay or a regression test that compares bits, look for an explicit repeatability scope: which platforms, versions, and execution modes does the guarantee cover? For results that must match the exact function rounded to a given precision, look for a correct-rounding contract in that precision. A guarantee for individual functions does not make a whole expression correctly rounded: if you add two rounded results, you already have two intermediate roundings.
See the OneMath elementary functions reference for the function list and rounding rules. For package setup, see getting started with OneMath.