Keep the sign of a negative base in Pow, and reject undefined powers - #102
Merged
matt-edmondson merged 1 commit intoSep 26, 2026
Merged
Conversation
…[patch] Pow computed |x|^p through Math.Log/Math.Exp and never restored the sign, so (-2)^3 returned 8 and (-1)^3 returned 1. A negative base now yields a negative result for odd integer powers. Pow also returned a value where none is defined. It now throws ArgumentException for a negative base with a non-integer power (it returned the real |x|^p), and DivideByZeroException for zero to a negative power (it returned zero). Callers that relied on those wrong values will now see an exception. Fixes #101 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01UHW69XTeuuLbfVdQdJ8uQh
|
matt-edmondson
deleted the
claude/significantnumber-101-pow-negative-base
branch
September 26, 2026 09:52
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 #101
Problem
SignificantNumber.Powcomputed|x|^pviaMath.Log/Math.Expand never restored the sign:(-2).Pow(3)8-8(-1).Pow(3)1-1(-2).Pow(0.5)1.4…(real, positive)ArgumentException0.Pow(-1)0DivideByZeroException(-3).Pow(2)99(unchanged)Fix
PowthrowsArgumentException.DivideByZeroException.Behaviour change: the two cases that now throw used to return a (wrong) value. The commit carries
[patch]because this is a bug fix. If you want it released as[minor]instead, retag it.Tests
New tests in
SignificantNumberTests:Pow_NegativeBaseAndOddExponent_ReturnsNegativeResultPow_NegativeOneAndOddExponent_ReturnsNegativeOnePow_NegativeBaseAndFractionalExponent_ThrowsArgumentExceptionPow_ZeroBaseAndNegativeExponent_ThrowsDivideByZeroExceptionWith the fix reverted, all 4 fail. With it, the full suite passes (99/99).
The triage comment suggested checking whether
PreciseNumber.Powhas the same log/exp bug. This PR does not cover that; it would need its own issue in PreciseNumber.🤖 Generated with Claude Code
https://claude.ai/code/session_01UHW69XTeuuLbfVdQdJ8uQh
Generated by Claude Code