Repository navigation
Take the logarithm of a subnormal base from its significand and exponent [patch] - #142
Merged
Merged
Conversation
…ent [patch] PowByLogarithm took ln|x| through value.To<double>(). A base between about 4.9e-324 and 2.2e-308 becomes a subnormal double with only a few significant digits, so a fractional power that brings the result back into normal range was wrong from the 4th or 5th digit while still reporting 7 significant digits: 1.23456789e-320 ^ 0.5000001 gave 1.111075e-160, not 1.111029e-160. When the base is not a normal double, build ln|x| from Log10OfMagnitude, which reads the significand and exponent and never passes the base through a double. Normal bases keep Math.Log, so their results are unchanged. Fixes #140 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017vfJW5pQJXg15qnY2s2Kwt
|
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.



Fixes #140
What was wrong
PowByLogarithmcomputedln|x|fromvalue.To<double>(). A base between about 4.9e-324 and 2.2e-308 converts to a subnormal double, which carries only a few significant digits. The fallback to the exact base-10 path only checked whether the result was a normal double, not the base. So when a fractional power brought the result back into normal range, the corrupted logarithm was used and the result still reported full precision:decimal)1.23456789e-320 ^ 0.50000011.23456789e-320 ^ -0.5000001Change
PowByLogarithmbuildsln|x|fromLog10OfMagnitude(value) * ln 10. That reads the significand and exponent directly, as the out-of-range fallback already does.Math.Log, so their results are unchanged. A base beyonddouble.MaxValuenow takes the same route. It used to go through the fallback, which gave the same answer.Tests
Pow_SubnormalDoubleBase_ReportsOnlyCorrectDigitswith both acceptance-criteria cases. It checks that 7 digits are reported and that every one of them matches a 60-digit reference.9000291…vs expected9000663…) and pass with it.Generated by Claude Code