Skip to content

Reject NaN in Vector0 guards with ArgumentException [patch] - #424

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/326-nan-guard-argument-exception
Oct 13, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/326-nan-guard-argument-exception

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #326

What changed

Vector0Guards.EnsureNonNegative and EnsurePositive tested the value with T.Sign, which throws ArithmeticException for double/float/Half NaN, so generated From{Unit} factories never reached their documented ArgumentException.

  • Both guards now check T.IsNaN first and throw ArgumentException("Magnitude must be a number; received NaN.", paramName).
  • The sign test becomes value < T.Zero / value <= T.Zero.

Tests

Added to Vector0InvariantTests:

  • each guard with double.NaN, float.NaN and Half.NaN → ArgumentException
  • generated factories Speed, Mass and Wavelength with NaN → ArgumentException
  • +∞ still passes EnsurePositive, and -∞ is still rejected by EnsureNonNegative

With the guard change reverted, the three NaN tests fail; with it applied, they pass. The full Semantics.Test suite passes on net10.0 (1645 passed, 0 failed).

🤖 Generated with Claude Code

https://claude.ai/code/session_01QbGcYckSzgr6jPyoNYhWvA


Generated by Claude Code

T.Sign(NaN) throws ArithmeticException for double, float and Half, so
the documented ArgumentException was never reached. Check T.IsNaN first,
then compare against zero instead of taking the sign.

Fixes #326

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01QbGcYckSzgr6jPyoNYhWvA
@sonarqubecloud

Copy link
Copy Markdown

@matt-edmondson
matt-edmondson merged commit 1aa6971 into main Oct 13, 2026
15 checks passed
@matt-edmondson
matt-edmondson deleted the fix/326-nan-guard-argument-exception branch October 13, 2026 08:22
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.

V0 From{Unit} factories throw ArithmeticException for NaN instead of the documented ArgumentException

2 participants