Skip to content

Report zero as not normal, and nothing as subnormal [patch] - #129

Merged
matt-edmondson merged 1 commit into
mainfrom
fix/isnormal-zero
Sep 28, 2026
Merged

matt-edmondson merged 1 commit into
mainfrom
fix/isnormal-zero

Conversation

@matt-edmondson

Copy link
Copy Markdown
Contributor

Fixes #122

What changed

  • IsNormal returned true for every value, so IsNormal(Zero) was true. int, decimal and BigInteger all report false for zero. It now returns !value.Significand.IsZero.
  • IsSubnormal was written as !IsNormal(value). With IsNormal fixed, that would have made IsSubnormal(Zero) true. It now returns false for every value, as BigInteger and decimal do.

This changes behavior callers can observe: generic math that uses IsNormal as a "safe to divide or log" guard now rejects PreciseNumber zero, the same way it rejects zero for the built-in types.

Tests

  • TestZeroIsNotNormal covers Zero and default. It fails on main.
  • TestNonZeroIntegerIsNormal and TestNonZeroFractionIsNormal cover positive, negative, very small and very large values.
  • TestNothingIsSubnormal covers zero and non-zero values. It guards against IsSubnormal going back to !IsNormal.
  • I reverted the library change and confirmed TestZeroIsNotNormal fails. With the fix, the full suite passes: dotnet test PreciseNumber.Test, 422/422.

🤖 Generated with Claude Code

https://claude.ai/code/session_01LasidbyRZfyxgW8Z9wQu9M


Generated by Claude Code

IsNormal returned true for every value, so IsNormal(Zero) was true where
int, decimal and BigInteger all report false. Generic math that guards a
division or a logarithm with IsNormal let PreciseNumber zero through.

IsNormal now returns false for zero only. IsSubnormal was written as
!IsNormal, which would have flipped it to true for zero; it now returns
false for every value, as BigInteger and decimal do, since the exponent
carries the magnitude and no value loses digits near zero.

Fixes #122

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LasidbyRZfyxgW8Z9wQu9M
@sonarqubecloud

Copy link
Copy Markdown

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.

IsNormal(Zero) returns true, unlike int/decimal/BigInteger, so generic math treats PreciseNumber zero as a normal number

2 participants