Skip to content

fix!: rejects NaN in Fraction#428

Merged
KSXGitHub merged 1 commit into
masterfrom
claude/awesome-pascal-4iouP
May 28, 2026
Merged

fix!: rejects NaN in Fraction#428
KSXGitHub merged 1 commit into
masterfrom
claude/awesome-pascal-4iouP

Conversation

@KSXGitHub
Copy link
Copy Markdown
Owner

@KSXGitHub KSXGitHub commented May 28, 2026

Resolves #425.

Problem

Fraction::new is documented to hold a value greater than or equal to 0 and less than 1, but it silently accepted NaN. Both bounds checks (value >= 1.0 and value < 0.0) are false for NaN, so the value slipped through to the constructor. This was reachable from the CLI via --min-ratio=NaN.

Change

  • Add an explicit is_nan() check at the start of Fraction::new.
  • Add a NotANumber variant to ConversionError (displayed as "not a number") so the invalid value is rejected at the boundary rather than relying on every downstream consumer to special-case NaN.
  • Add a test covering "NaN".parse::<Fraction>().

This is a breaking change: Fraction::new(NaN) now returns Err(NotANumber) instead of Ok, and the public ConversionError enum gains a new variant.

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
@KSXGitHub KSXGitHub marked this pull request as ready for review May 28, 2026 16:12
@KSXGitHub KSXGitHub merged commit ef65884 into master May 28, 2026
15 checks passed
@KSXGitHub KSXGitHub deleted the claude/awesome-pascal-4iouP branch May 28, 2026 16:13
@github-actions
Copy link
Copy Markdown

Performance Regression Reports

commit: 5354aa4

There are no regressions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Fraction::new silently accepts NaN

2 participants