summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarco Bodrato <bodrato@mail.dm.unipi.it>2022-09-08 22:02:50 +0200
committerMarco Bodrato <bodrato@mail.dm.unipi.it>2022-09-08 22:02:50 +0200
commitdbcd5a39702fa91d757d412e422a945ed079ec35 (patch)
treec6632a848173673b78877309341048a90334749c
parent7c92275fe4133ce24c268078e1294f4fba4ecd43 (diff)
downloadgmp-dbcd5a39702fa91d757d412e422a945ed079ec35.tar.gz
mini-gmp/tests/t-powm.c: Test some corner cases
-rw-r--r--mini-gmp/ChangeLog5
-rw-r--r--mini-gmp/mini-gmp.c3
-rw-r--r--mini-gmp/tests/t-powm.c28
3 files changed, 34 insertions, 2 deletions
diff --git a/mini-gmp/ChangeLog b/mini-gmp/ChangeLog
index b0bde8165..ae5d10515 100644
--- a/mini-gmp/ChangeLog
+++ b/mini-gmp/ChangeLog
@@ -1,9 +1,14 @@
+2022-09-08 Marco Bodrato <bodrato@mail.dm.unipi.it>
+
+ * tests/t-powm.c: Test some corner cases (e.g. 1^0 mod 1).
+
2022-09-05 Niels Möller <nisse@lysator.liu.se>
* mini-gmp.c (mpz_powm): Fix case of x^0 (mod 1), should be 0.
Reported by Guido Vranken.
2022-05-29 Marco Bodrato <bodrato@mail.dm.unipi.it>
+
* mini-mpq.c (mpq_helper_2exp): New helper (internal) function.
2022-04-18 Niels Möller <nisse@lysator.liu.se>
diff --git a/mini-gmp/mini-gmp.c b/mini-gmp/mini-gmp.c
index 59db06f7e..ea037b801 100644
--- a/mini-gmp/mini-gmp.c
+++ b/mini-gmp/mini-gmp.c
@@ -1,8 +1,9 @@
/* mini-gmp, a minimalistic implementation of a GNU GMP subset.
Contributed to the GNU project by Niels Möller
+ Additional functionalities and improvements by Marco Bodrato.
-Copyright 1991-1997, 1999-2021 Free Software Foundation, Inc.
+Copyright 1991-1997, 1999-2022 Free Software Foundation, Inc.
This file is part of the GNU MP Library.
diff --git a/mini-gmp/tests/t-powm.c b/mini-gmp/tests/t-powm.c
index d6c108d47..1cce9b5fb 100644
--- a/mini-gmp/tests/t-powm.c
+++ b/mini-gmp/tests/t-powm.c
@@ -1,6 +1,6 @@
/*
-Copyright 2012, Free Software Foundation, Inc.
+Copyright 2012, 2022, Free Software Foundation, Inc.
This file is part of the GNU MP Library test suite.
@@ -53,6 +53,32 @@ testmain (int argc, char **argv)
abort ();
}
}
+
+ /* res >= 0, come from the random choices above, */
+ if (mpz_cmp_ui (res, 1) <= 0) /* if too small, */
+ mpz_add_ui (res, res, 9); /* add an arbitrary value. */
+
+ mpz_set_ui (e, 0);
+ /* Test the case m^0 (mod m), expect 1 (m is greater than 1). */
+ mpz_powm (res, res, e, res);
+ if (mpz_cmp_ui (res, 1) != 0)
+ {
+ fprintf (stderr, "mpz_powm failed: b=m, e=0; 1 expected,\n");
+ dump ("m", res);
+ dump ("r", res);
+ abort ();
+ }
+
+ /* Now res is 1. */
+ /* Test the case 1^0 (mod 1), expect 0. */
+ mpz_powm (res, res, e, res);
+ if (mpz_size (res))
+ {
+ fprintf (stderr, "mpz_powm failed: b=1, e=0, m=1; 0 expected,\n");
+ dump ("r", res);
+ abort ();
+ }
+
mpz_clear (b);
mpz_clear (e);
mpz_clear (m);