You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
V0 From{Unit} factories throw ArithmeticException for NaN instead of the documented ArgumentException #326
Vector0Guards.EnsureNonNegative and EnsurePositive (Semantics.Quantities/Vector0Guards.cs around lines 34 and 60) test the value with T.Sign(value). For double, float and Half, Sign(NaN) throws ArithmeticException ("Function does not accept floating point Not-a-Number values."), so the documented ArgumentException is never reached.
Repro
Speed<double>.FromMeterPerSecond(double.NaN), Mass<double>.FromKilogram(double.NaN) and Wavelength<double>.FromMeter(double.NaN) all throw ArithmeticException.
Why it matters
Four places say this should be an ArgumentException:
the guard XML docs;
every generated factory's XML (for example Speed.g.cs around line 101), which documents only ArgumentException;
the Quantities docs;
CLAUDE.md ("Throw ArgumentException for validation failures").
A caller that validates user input by catching ArgumentException gets an unhandled ArithmeticException instead. #285's suggested fix routes scalar * and / through these guards, which would spread the same exception to arithmetic results such as 0 * ∞.
Suggested fix
In both guards, check T.IsNaN(value) first and throw ArgumentException($"Magnitude must be a number; received NaN.", paramName). Then compare with value < T.Zero / value <= T.Zero rather than T.Sign.
Acceptance: add tests for both guards with double.NaN, float.NaN and Half.NaN that assert ArgumentException, plus a generated-factory test such as Speed<double>.FromMeterPerSecond(double.NaN).
Activity
matt-edmondson commentedon Sep 29, 2026
Triage
ArithmeticExceptioninstead of the documentedArgumentException. Callers that catchArgumentExceptionto validate input are affected. The priority goes up if Vector0 magnitudes go negative through unary minus and scalar * and /:-Temperature.FromKelvin(300)is −300 K #285's fix routes scalar arithmetic through these guards, so fix this one first or in the same PR.Semantics.Quantities(Vector0Guards.EnsureNonNegative/EnsurePositive)-Temperature.FromKelvin(300)is −300 K #285.Suggested next step: check
T.IsNaNfirst, then compare with</<=rather thanT.Sign. Add NaN tests fordouble,floatandHalf.Generated by Claude Code