Fix DASHU-007: directed log2 uses dashu's correctly-rounded log2() - #1
Open
cmpute wants to merge 1 commit into
Open
Fix DASHU-007: directed log2 uses dashu's correctly-rounded log2()#1cmpute wants to merge 1 commit into
cmpute wants to merge 1 commit into
Conversation
The Dashu backend's DirectedUnary<Log2> called FBig::log2_bounds() (a coarse f32-precision interval) and rounded that bound, instead of dashu's correctly-rounded FBig::log2(). As a result every directed log2 differed from the MPFR oracle by up to a few ULPs across all magnitude ranges (finding DASHU-007 — all four reproducers fired). dashu's log2() is correctly rounded as of 0.6.0-rc.1 (d4fde06), so route log2 through the same eval_adaptive directed_unary! path already used for ln/ln1p/sqrt, deleting the bespoke directed_log2! macro. This also adds Nearest support that the old impl returned Unsupported for. Verified: all four DASHU-007 reproducers now pass (no OPENDP_NUM_VIOLATION). Co-Authored-By: Claude <noreply@anthropic.com>
Author
|
I plan to release a major version 0.6 for dashu soon, this pr depends on v0.6 features. |
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.
Summary
The
Dashubackend's directedlog2(DirectedUnary<Log2, _>) calledFBig::log2_bounds()— a crudef32-precision interval estimate — and rounded that bound, instead of dashu's correctly-roundedFBig::log2(). As a result every directedlog2differed from the MPFR oracle by up to a few ULPs across all magnitude ranges (DASHU-007 — all four reproducers fired:DASHU-007.input,-direct,-one,-max).dashu's
log2()is correctly rounded as of0.6.0-rc.1(d4fde06), so this PR switches the adapter to it, mirroring the existingLn/Ln1p/Sqrtimpls.Root cause
src/backend/dashu.rs— the bespokedirected_log2!macro:log2_bounds()returns(f32, f32). Rounding anf32bound tof64/f32cannot match a correctly-rounded result except by coincidence, so the directed result was routinely off. The historical reason for the workaround was that dashu'slog2was not previously correctly rounded; that no longer holds.Fix
Delete the
directed_log2!macro and route through the standarddirected_unary!path already used forLn(same domainx > 0, sameeval_adaptiveconvergence), callingx.log2():The now-unused
EstimatedLog2import (which providedlog2_bounds) is dropped.Behavior notes
x <= 0still returns a domain error (matching the previous impl andLn).Nearestnow works (previously returnedUnsupported), routing throughHalfEvenlike the other transcendentals.>= 0.6.0-rc.1(d4fde06) for the correctly-roundedlog2.Verification
All four registered DASHU-007 reproducers now pass (no
OPENDP_NUM_VIOLATION):Independent dashu-side confirmation that
log2()itself is correctly rounded on these inputs at p=24/53:log2(1.0)→0;log2(2^-1022)→−1022(exact);log2(f64::MAX)→1023.9999999999998underDown/1024underUp(Up ≥ Down). After this PR the adapter reaches those same values instead of thelog2_bounds()approximation.🤖 Generated with Claude Code