Repository navigation
Return ±1 from (-1).Pow for an integer power beyond double range [patch] - #136
Merged
Merged
Conversation
Pow special-cased a base of One but not NegativeOne, so (-1)^n for an
integer n outside the range of a double fell through to PowByLogarithm,
computed 0 * infinity = NaN and threw OverflowException("The result is
too small to represent."). (-1)^n is exact for any integer n, so return
One for an even power and NegativeOne for an odd one, decided on the
PreciseNumber without going through a double. A non-integer power of -1
still throws ArgumentException.
Fixes #117
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01MiwudJMQgsVwkkrRfMfwG2
|
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 #117
What was wrong
Powspecial-cased a base ofOnebut notNegativeOne. For an integer power outside the range of a double,(-1)^nfell through toPowByLogarithm, which computed0 · ∞ = NaNand threwOverflowException("The result is too small to represent.").Change
Next to the
Equal(this, One)check, a base of -1 with an integer power now returnsOnefor an even power andNegativeOnefor an odd one. The parity check works on thePreciseNumberdirectly, so it never goes through a double. A non-integer power of -1 still throwsArgumentException, as before.Tests
In
SignificantNumberRangeTests:Pow_NegativeOneToAnEvenIntegerBeyondDoubleRange_ReturnsOnecovers2E308,-1E400,-3E400, and1E308, which is still inside double range.Pow_NegativeOneToAnOddIntegerBeyondDoubleRange_ReturnsNegativeOnecovers2…(310 zeros)…1and its negation.Pow_NegativeOneToANonIntegerPower_StillThrowsArgumentExceptionWith the library change reverted, 4 of these fail: the three out-of-range even rows and the odd test. With the change, the full suite passes locally on net10.0 (190/190).
Generated by Claude Code