From 66358e9278b999aeed9b7f13cc61540c93e19f3f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Thu, 18 Jun 2026 14:03:41 +0000 Subject: [PATCH 1/2] feat: add IsPositive, IsNegative, and IsZero predicates Add three AggressiveInlining static predicates that complement the existing IsInteger helper and complete the sign/zero API: - IsPositive(value): true when RawValue > 0 - IsNegative(value): true when RawValue < 0 - IsZero(value): true when RawValue == 0 These are commonly expected on numeric types and lay the groundwork for implementing INumber/ISignedNumber in a future PR. 3 new tests; total 1440, all passing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/FixedPointNano/FixedPointNano.cs | 24 ++++++++++++++ .../FixedPointNanoTests.cs | 32 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/src/FixedPointNano/FixedPointNano.cs b/src/FixedPointNano/FixedPointNano.cs index db16af6..aacb67e 100644 --- a/src/FixedPointNano/FixedPointNano.cs +++ b/src/FixedPointNano/FixedPointNano.cs @@ -135,6 +135,30 @@ public static bool IsInteger(FixedPointNano value) return value.RawValue % Scale == 0; } + /// Returns if is strictly greater than zero. + /// The value to test. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsPositive(FixedPointNano value) + { + return value.RawValue > 0; + } + + /// Returns if is strictly less than zero. + /// The value to test. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsNegative(FixedPointNano value) + { + return value.RawValue < 0; + } + + /// Returns if is exactly zero. + /// The value to test. + [MethodImpl(MethodImplOptions.AggressiveInlining)] + public static bool IsZero(FixedPointNano value) + { + return value.RawValue == 0; + } + public static FixedPointNano FromDecimal(decimal value) { var scaledValue = decimal.Round(value * Scale, 0, MidpointRounding.ToEven); diff --git a/tests/FixedPointNano.Tests/FixedPointNanoTests.cs b/tests/FixedPointNano.Tests/FixedPointNanoTests.cs index 2795000..0e2a5b6 100644 --- a/tests/FixedPointNano.Tests/FixedPointNanoTests.cs +++ b/tests/FixedPointNano.Tests/FixedPointNanoTests.cs @@ -36,6 +36,38 @@ public void IsIntegerShouldDetectWholeness() Assert.That(FixedPointNano.IsInteger(FixedPointNano.FromDecimal(-2m)), Is.True); } + [Test] + public void IsPositiveShouldReturnTrueOnlyForPositiveValues() + { + Assert.That(FixedPointNano.IsPositive(FixedPointNano.Zero), Is.False); + Assert.That(FixedPointNano.IsPositive(FixedPointNano.Epsilon), Is.True); + Assert.That(FixedPointNano.IsPositive(FixedPointNano.One), Is.True); + Assert.That(FixedPointNano.IsPositive(FixedPointNano.MaxValue), Is.True); + Assert.That(FixedPointNano.IsPositive(FixedPointNano.NegativeOne), Is.False); + Assert.That(FixedPointNano.IsPositive(FixedPointNano.MinValue), Is.False); + } + + [Test] + public void IsNegativeShouldReturnTrueOnlyForNegativeValues() + { + Assert.That(FixedPointNano.IsNegative(FixedPointNano.Zero), Is.False); + Assert.That(FixedPointNano.IsNegative(FixedPointNano.Epsilon), Is.False); + Assert.That(FixedPointNano.IsNegative(FixedPointNano.One), Is.False); + Assert.That(FixedPointNano.IsNegative(FixedPointNano.MaxValue), Is.False); + Assert.That(FixedPointNano.IsNegative(FixedPointNano.NegativeOne), Is.True); + Assert.That(FixedPointNano.IsNegative(FixedPointNano.MinValue), Is.True); + } + + [Test] + public void IsZeroShouldReturnTrueOnlyForZero() + { + Assert.That(FixedPointNano.IsZero(FixedPointNano.Zero), Is.True); + Assert.That(FixedPointNano.IsZero(FixedPointNano.Epsilon), Is.False); + Assert.That(FixedPointNano.IsZero(new FixedPointNano(-1L)), Is.False); + Assert.That(FixedPointNano.IsZero(FixedPointNano.One), Is.False); + Assert.That(FixedPointNano.IsZero(FixedPointNano.NegativeOne), Is.False); + } + [Test] public void FractionalPartShouldReturnDecimalComponent() { From 69fc378f46e75de08a458b4bb8301a45ff5c49c5 Mon Sep 17 00:00:00 2001 From: Nich Overend Date: Thu, 18 Jun 2026 18:44:22 +0100 Subject: [PATCH 2/2] Potential fix for pull request finding Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- tests/FixedPointNano.Tests/FixedPointNanoTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/FixedPointNano.Tests/FixedPointNanoTests.cs b/tests/FixedPointNano.Tests/FixedPointNanoTests.cs index 0e2a5b6..2a6e7bf 100644 --- a/tests/FixedPointNano.Tests/FixedPointNanoTests.cs +++ b/tests/FixedPointNano.Tests/FixedPointNanoTests.cs @@ -63,7 +63,7 @@ public void IsZeroShouldReturnTrueOnlyForZero() { Assert.That(FixedPointNano.IsZero(FixedPointNano.Zero), Is.True); Assert.That(FixedPointNano.IsZero(FixedPointNano.Epsilon), Is.False); - Assert.That(FixedPointNano.IsZero(new FixedPointNano(-1L)), Is.False); + Assert.That(FixedPointNano.IsZero(-FixedPointNano.Epsilon), Is.False); Assert.That(FixedPointNano.IsZero(FixedPointNano.One), Is.False); Assert.That(FixedPointNano.IsZero(FixedPointNano.NegativeOne), Is.False); }