---
title: "Correctly rounded vs. deterministic math"
url: https://recursiveai.org/onemath/articles/correctly-rounded-vs-deterministic-math/
description: "Correct rounding rounds the exact result once under a specified rounding mode. Deterministic math returns the same bits for the same inputs."
date: 2026-11-18
author: OneMath team
---

# Correctly rounded vs. deterministic math

Correct rounding rounds the exact result once under a specified rounding mode. Deterministic math returns the same bits for the same inputs.

November 18, 2026 · OneMath team

OneMath is a deterministic .NET math library with [correctly rounded elementary functions](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/docs/functions.md#L3-L10) (such as exp, log, pow, and sin), licensed [MIT](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/LICENSE-MIT) or [Apache-2.0](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/LICENSE-APACHE). [NuGet](https://www.nuget.org/packages/RecursiveAI.OneMath/1.0.0) · [GitHub](https://github.com/recursive-ai-oss/onemath-csharp) · [Docs](https://recursiveai.org/onemath/docs/)

`dotnet add package RecursiveAI.OneMath --version 1.0.0`

*Program.cs · .NET 10*

```
using RecursiveAI.OneMath;
var value = Math64.Exp2(-1075);
var bits = BitConverter.DoubleToUInt64Bits(value);
Console.WriteLine($"0x{bits:X16}");
```

*Output · OneMath 1.0.0*

```
0x0000000000000000
```

For 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](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/docs/functions.md#L3-L10) 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](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/README.md#L3), and [no 1.x minor or patch release changes an existing result](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/README.md#L47).

Microsoft’s .NET 10 docs for [`System.Math.Sin`](https://learn.microsoft.com/en-us/dotnet/api/system.math.sin?view=net-10.0#remarks) and [`System.Math.Exp`](https://learn.microsoft.com/en-us/dotnet/api/system.math.exp?view=net-10.0#remarks) 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](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/tests/OneMath.Tests/Functions/SpecialValueTests.cs#L114-L120) 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](https://github.com/recursive-ai-oss/onemath-csharp/blob/1986f32ecb9f5f3001c0121484f104c489720334/docs/functions.md#L7-L10) 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](https://www.nuget.org/packages/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.

*Terminal · .NET 10*

```
dotnet new console
dotnet add package RecursiveAI.OneMath --version 1.0.0
```

*Program.cs · .NET 10*

```
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);
```

*Output · OneMath 1.0.0*

```
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](https://recursiveai.org/onemath/docs/functions/) for the function list and rounding rules. For package setup, see [getting started with OneMath](https://recursiveai.org/onemath/docs/getting-started/).
