Repository navigation
fix: float32 Exp and Log correctly rounded, proven over every float32 - #87
Merged
Merged
Conversation
An exhaustive test runs all 2^32 float32 inputs and certifies each result in one of three ways: the float64 intermediate (0.504 ULP) is more than 2 float64 ULP from both float32 midpoints, or it is far outside float32's range, or a 300-bit reference decides the rounding. The certifier is tested on planted midpoints and the overflow boundary. That boundary case was a bug, caught by the test. A kernel sabotaged one ULP up fails 76% / 50% of the inputs. Exp: 0 incorrectly rounded (2 decided by the reference), on darwin/arm64 and linux/amd64. Log: 5 inputs double-rounded wrong, e.g. log(9.47263622) gave 0x400fe5e8, not 0x400fe5e7. Fixed with the usual exception table: a result within 8 float64 ULP of a midpoint is looked up among the 24 inputs that come within 2 ULP, each with its 300-bit-reference rounding. With the table, 0 incorrectly rounded on both architectures. The check costs nothing measurable on Zen 3. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…not reach them) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
float32
ExpandLogare now correctly rounded: every result is the float32 nearest the exact value. This is proven over all 2³² inputs.The proof:
TestExp32CorrectlyRoundedandTestLog32CorrectlyRoundedrun every bit pattern withNDARRAY_EXHAUSTIVE=1; CI samples every 65 537th. Each result is certified in one of three ways:refExp/refLog) decides the rounding.Controls:
Fix:
Log's double rounding was wrong for 5 inputs (e.g. log(9.47263622) =0x400fe5e8, not0x400fe5e7). The fix is a midpoint check (one integer comparison) plus a table of the 24 near-midpoint inputs with their 300-bit-reference roundings. It costs nothing measurable (−4%, p = 0.07, host at load 15).Results, run on each real machine:
ExpLogloong64 is covered by CI's sampled run only, because the Loongson host refuses our key.
NumPy's float32 kernels are documented at 2.52 ULP (exp) and 3.83 ULP (log) in their sources.
🤖 Generated with Claude Code