Merge pull request #522 from czurnieden/complete_mp_is_square Introduced 0 (zero) to mp_is_square as a perfect square
diff --git a/demo/test.c b/demo/test.c
index 4ce8131..b9ef509 100644
--- a/demo/test.c
+++ b/demo/test.c
@@ -677,6 +677,17 @@ static int test_mp_is_square(void)
DOR(mp_init_multi(&a, &b, NULL));
+
+ /* Domain is {x \in \mathbb{Z} : x \le 0} */
+ mp_set_l(&a, -1);
+ EXPECT(mp_is_square(&a, &res) == MP_VAL);
+ EXPECT(!res);
+
+ /* Zero is a perfect square, too */
+ mp_zero(&a);
+ DO(mp_is_square(&a, &res));
+ EXPECT(res);
+
for (i = 0; i < 1000; ++i) {
printf("%6d\r", i);
fflush(stdout);
diff --git a/mp_is_square.c b/mp_is_square.c
index db1cb3f..d2856e2 100644
--- a/mp_is_square.c
+++ b/mp_is_square.c
@@ -41,6 +41,7 @@ mp_err mp_is_square(const mp_int *arg, bool *ret)
}
if (mp_iszero(arg)) {
+ *ret = true;
return MP_OKAY;
}