compare exact values in BigInteger and BigDecimal Number range checks#402
Closed
sahvx655-wq wants to merge 1 commit into
Closed
compare exact values in BigInteger and BigDecimal Number range checks#402sahvx655-wq wants to merge 1 commit into
sahvx655-wq wants to merge 1 commit into
Conversation
7 tasks
Member
|
To reduce code duplication, I'll merging #404 instead of this PR. You will be credited in |
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.
Carrying on from the BigInteger/BigDecimal conversion review after #400 and #401, the inherited
Number-typed range overloads stood out: the type-specific overloads now compare exact values, butminValue(Number, Number),maxValue(Number, Number)and theisInRange(Number, Number, Number)that delegates to them still narrow throughvalue.longValue()/value.doubleValue()inAbstractNumberValidator. The existing range tests only exercise the type-specific overloads, so nothing flagged it. ABigIntegerpast the long range truncates before the comparison (isInRange(2^64 + 50, 5, 100)wraps to 50 and is wrongly accepted), and onBigDecimalValidatora value differing from the bound only beyond double precision (2^53 + 1 versus 2^53) rounds onto the bound and is misclassified.Override the two
Numberoverloads in each validator to compare the exactBigInteger/BigDecimalwithcompareTo;isInRangeinherits the correct behaviour through virtual dispatch. Keeping the fix beside the type-specific overloads means all four entry points agree, and theBigDecimaloverride falls back to thedoubleValue()comparison for a non-finite bound so the infinity behaviour from #401 stays intact.