fix off-by-one rejecting trailing nan/infinity in parseNumber#326
Merged
aherbert merged 2 commits intoJun 9, 2026
Merged
Conversation
aherbert
reviewed
Jun 9, 2026
| public void testParseRealInfinity() { | ||
| Complex positive = Complex.ofCartesian(Double.POSITIVE_INFINITY, 0); | ||
| Assert.assertEquals(positive, complexFormat.parse("(Infinity)")); | ||
| Complex negative = Complex.ofCartesian(Double.NEGATIVE_INFINITY, 0); |
Contributor
There was a problem hiding this comment.
This should test the round-trip:
Assert.assertEquals(positive, complexFormat.parse(complexFormat.format(positive)));
Assert.assertEquals(negative, complexFormat.parse(complexFormat.format(negative)));Parsing should also test special values in the imaginary part:
Complex.ofCartesian(1.23, Double.NaN);
Complex.ofCartesian(1.23, Double.POSITIVE_INFINITY);
Complex.ofCartesian(1.23, Double.NEGATIVE_INFINITY);
Contributor
Author
There was a problem hiding this comment.
Done. The infinity test now checks the round trip for both signs, and I added testParseImaginarySpecialValue covering NaN, +Infinity and -Infinity in the imaginary part (parsed back from format output). All pass with the patch.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #326 +/- ##
============================================
+ Coverage 86.54% 87.15% +0.61%
+ Complexity 9787 89 -9698
============================================
Files 532 499 -33
Lines 35516 33463 -2053
Branches 6194 5833 -361
============================================
- Hits 30738 29166 -1572
+ Misses 3518 3174 -344
+ Partials 1260 1123 -137 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
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.
CompositeFormat.parseNumber checks endIndex < source.length() before matching a special value like (NaN) or (Infinity), so a special-value token that runs to the final character of the input is never recognised. This breaks the format/parse round trip for a real-only NaN or infinity in ComplexFormat, where parse throws MathParseException on the very string format produced. Widening the comparison to endIndex <= source.length() lets a special value ending the input parse, which also covers RealVectorFormat and RealMatrixFormat as they share the same helper.