Repository: apytypes/apytypes (language: python)

Issue:
`_is_positive` not giving correct result
`_is_positive` is returning `False` on a positive number.

Example:
```Python
from apytypes import APyFixed
x = APyFixed(1, int_bits=1, frac_bits=1080)
x._is_positive # False
x._is_negative # False
x.is_zero # False

x > 0 # True
x < 0 # False
x == 0 # False
```
I'm not sure if `_is_positive` and `_is_negative` should be accessible from the Python API to begin with, from what I remember we decided to remove it as it can be replaced by comparisons against zero. However I stumbled upon this when I tried to use the corresponding C++ function.


Discussion / hints:
Private method, so not documented what it does. But probably makes sense that the corresponding C++-function works as one may guess...

Fix patch:
diff --git a/src/apyfixed.cc b/src/apyfixed.cc
index 3ec050468..2e65628ca 100644
--- a/src/apyfixed.cc
+++ b/src/apyfixed.cc
@@ -469,10 +469,7 @@ bool APyFixed::is_negative() const noexcept
     return limb_vector_is_negative(_data.begin(), _data.end());
 }
 
-bool APyFixed::is_positive() const noexcept
-{
-    return mp_limb_signed_t(_data.back()) > 0;
-}
+bool APyFixed::is_positive() const noexcept { return !is_negative() && !is_zero(); }
 
 bool APyFixed::is_zero() const noexcept
 {


Test patch:
diff --git a/lib/test/apyfixed/test_arithmetic.py b/lib/test/apyfixed/test_arithmetic.py
index 234248f14..758ea03c8 100644
--- a/lib/test/apyfixed/test_arithmetic.py
+++ b/lib/test/apyfixed/test_arithmetic.py
@@ -255,6 +255,32 @@ def test_unary_minus():
     assert not (-a)._is_negative
 
 
+def test_positive_negative_zero():
+    assert not APyFixed(0, int_bits=4, frac_bits=4)._is_positive
+    assert APyFixed(0, int_bits=4, frac_bits=4).is_zero
+    assert not APyFixed(0, int_bits=4, frac_bits=4)._is_negative
+
+    assert APyFixed(1, int_bits=4, frac_bits=4)._is_positive
+    assert not APyFixed(1, int_bits=4, frac_bits=4).is_zero
+    assert not APyFixed(1, int_bits=4, frac_bits=4)._is_negative
+
+    assert not APyFixed(-1, int_bits=4, frac_bits=4)._is_positive
+    assert not APyFixed(-1, int_bits=4, frac_bits=4).is_zero
+    assert APyFixed(-1, int_bits=4, frac_bits=4)._is_negative
+
+    assert not APyFixed(0, int_bits=4, frac_bits=10000)._is_positive
+    assert APyFixed(0, int_bits=4, frac_bits=10000).is_zero
+    assert not APyFixed(0, int_bits=4, frac_bits=10000)._is_negative
+
+    assert APyFixed(1, int_bits=4, frac_bits=10000)._is_positive
+    assert not APyFixed(1, int_bits=4, frac_bits=10000).is_zero
+    assert not APyFixed(1, int_bits=4, frac_bits=10000)._is_negative
+
+    assert not APyFixed(-1, int_bits=4, frac_bits=10000)._is_positive
+    assert not APyFixed(-1, int_bits=4, frac_bits=10000).is_zero
+    assert APyFixed(-1, int_bits=4, frac_bits=10000)._is_negative
+
+
 def test_abs():
     a = APyFixed(-3, 2, 1)
     assert abs(a).is_identical(APyFixed(3, 3, 1))