Skip to content

feat(major): Make NaN signalling (trap on use)#2

Merged
hassila merged 5 commits intomainfrom
signal-nan
Mar 27, 2026
Merged

feat(major): Make NaN signalling (trap on use)#2
hassila merged 5 commits intomainfrom
signal-nan

Conversation

@hassila
Copy link
Copy Markdown
Contributor

@hassila hassila commented Mar 27, 2026

Summary

  • NaN now traps immediately when used in any computation (arithmetic, rounding, negation, abs, pow) instead of silently propagating
  • .nan sentinel value, .isNaN, and representation paths (description, doubleValue, decimalValue, codable, formatting, comparisons) remain unchanged
  • All 24 quiet-NaN propagation sites across 7 source files converted to precondition checks
  • Tests updated to expect traps via processExitsWith: .failure

BREAKING CHANGE: Operations on NaN now trap instead of returning NaN. Users who relied on quiet propagation must check .isNaN before operating.

Motivation

Quiet NaN propagation can mask bugs — a NaN enters a computation chain and silently corrupts all downstream results, surfacing far from the original error. Signalling NaN catches misuse at the point of error, consistent with how overflow already traps (matching Swift Int semantics).

Test plan

  • swift build compiles cleanly
  • swift test — all 564 tests pass
  • swiftlint lint — 0 violations

🤖 Generated with Claude Code

NaN remains as a sentinel value (.nan, .isNaN) but now traps immediately
when used in any computation (arithmetic, rounding, negation, abs, pow).
Representation paths (description, doubleValue, decimalValue, codable)
still handle NaN gracefully. This catches NaN misuse at the point of
error rather than letting it propagate silently through calculations.

BREAKING CHANGE: Operations on NaN now trap instead of returning NaN.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hassila hassila changed the title feat!: Make NaN signalling (trap on use) feat(major): Make NaN signalling (trap on use) Mar 27, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 27, 2026

Codecov Report

❌ Patch coverage is 98.18182% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.62%. Comparing base (52bc71f) to head (06630d2).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
Sources/FixedPointDecimal/FixedPointDecimal.swift 70.00% 3 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main       #2      +/-   ##
==========================================
+ Coverage   97.79%   98.62%   +0.83%     
==========================================
  Files          28       28              
  Lines        3795     3840      +45     
==========================================
+ Hits         3711     3787      +76     
+ Misses         84       53      -31     
Files with missing lines Coverage Δ
...xedPointDecimal/FixedPointDecimal+Arithmetic.swift 100.00% <100.00%> (ø)
.../FixedPointDecimal/FixedPointDecimal+Numeric.swift 100.00% <100.00%> (ø)
...FixedPointDecimal/FixedPointDecimal+Overflow.swift 100.00% <100.00%> (ø)
...FixedPointDecimal/FixedPointDecimal+Rounding.swift 97.06% <100.00%> (ø)
.../FixedPointDecimal/FixedPointDecimal+SwiftUI.swift 90.91% <ø> (ø)
Tests/FixedPointDecimalTests/ArithmeticTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/BasicTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/ConversionTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/EdgeCaseTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/OverflowTests.swift 100.00% <100.00%> (ø)
... and 5 more

... and 2 files with indirect coverage changes

Files with missing lines Coverage Δ
...xedPointDecimal/FixedPointDecimal+Arithmetic.swift 100.00% <100.00%> (ø)
.../FixedPointDecimal/FixedPointDecimal+Numeric.swift 100.00% <100.00%> (ø)
...FixedPointDecimal/FixedPointDecimal+Overflow.swift 100.00% <100.00%> (ø)
...FixedPointDecimal/FixedPointDecimal+Rounding.swift 97.06% <100.00%> (ø)
.../FixedPointDecimal/FixedPointDecimal+SwiftUI.swift 90.91% <ø> (ø)
Tests/FixedPointDecimalTests/ArithmeticTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/BasicTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/ConversionTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/EdgeCaseTests.swift 100.00% <100.00%> (ø)
Tests/FixedPointDecimalTests/OverflowTests.swift 100.00% <100.00%> (ø)
... and 5 more

... and 2 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f33510e...06630d2. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

hassila and others added 2 commits March 27, 2026 13:49
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Cover signed and unsigned integer exact conversion including success,
fractional rejection, NaN rejection, and out-of-range rejection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 27, 2026

hassila and others added 2 commits March 27, 2026 13:51
Cover concrete overloads for Int, Int64, and Int32 exact conversion
from FixedPointDecimal: success, fractional rejection, NaN rejection,
and out-of-range rejection.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…cand:exponent: traps

Also fix stale NaN-propagation example in .nan doc comment.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hassila hassila merged commit 786e963 into main Mar 27, 2026
11 of 12 checks passed
@hassila hassila deleted the signal-nan branch March 27, 2026 13:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants