fix!: rejects NaN in Fraction#428
Merged
Merged
Conversation
NaN passed both the upper-bound and lower-bound comparisons because every ordered comparison against NaN is false, so an invalid value reached the constructor. Add an explicit is_nan check and a NotANumber variant so the value is rejected at the boundary instead of relying on downstream consumers to special-case NaN. https://claude.ai/code/session_01SEknK8pBtZzArSLx7wvrLj
Performance Regression Reportscommit: 5354aa4 There are no regressions. |
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.
Resolves #425.
Problem
Fraction::newis documented to hold a value greater than or equal to 0 and less than 1, but it silently acceptedNaN. Both bounds checks (value >= 1.0andvalue < 0.0) arefalseforNaN, so the value slipped through to the constructor. This was reachable from the CLI via--min-ratio=NaN.Change
is_nan()check at the start ofFraction::new.NotANumbervariant toConversionError(displayed as "not a number") so the invalid value is rejected at the boundary rather than relying on every downstream consumer to special-caseNaN."NaN".parse::<Fraction>().This is a breaking change:
Fraction::new(NaN)now returnsErr(NotANumber)instead ofOk, and the publicConversionErrorenum gains a new variant.