[Gmp-commit] /var/hg/gmp: mini-gmp/tests/t-powm.c: Test some corner cases

mercurial at gmplib.org mercurial at gmplib.org
Thu Sep 8 22:08:07 CEST 2022


details:   /var/hg/gmp/rev/feb796a7f683
changeset: 18369:feb796a7f683
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Thu Sep 08 22:02:50 2022 +0200
description:
mini-gmp/tests/t-powm.c: Test some corner cases

diffstat:

 mini-gmp/ChangeLog      |   5 +++++
 mini-gmp/mini-gmp.c     |   5 +++--
 mini-gmp/tests/t-powm.c |  28 +++++++++++++++++++++++++++-
 3 files changed, 35 insertions(+), 3 deletions(-)

diffs (77 lines):

diff -r 137fe73908e1 -r feb796a7f683 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Mon Sep 05 21:05:59 2022 +0200
+++ b/mini-gmp/ChangeLog	Thu Sep 08 22:02:50 2022 +0200
@@ -1,9 +1,14 @@
+2022-09-08 Marco Bodrato <bodrato at 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 at 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 at mail.dm.unipi.it>
+
 	* mini-mpq.c (mpq_helper_2exp): New helper (internal) function.
 
 2022-04-18  Niels Möller  <nisse at lysator.liu.se>
diff -r 137fe73908e1 -r feb796a7f683 mini-gmp/mini-gmp.c
--- a/mini-gmp/mini-gmp.c	Mon Sep 05 21:05:59 2022 +0200
+++ b/mini-gmp/mini-gmp.c	Thu Sep 08 22:02:50 2022 +0200
@@ -1,8 +1,9 @@
 /* mini-gmp, a minimalistic implementation of a GNU GMP subset.
 
    Contributed to the GNU project by Niels Möller
-
-Copyright 1991-1997, 1999-2021 Free Software Foundation, Inc.
+   Additional functionalities and improvements by Marco Bodrato.
+
+Copyright 1991-1997, 1999-2022 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
diff -r 137fe73908e1 -r feb796a7f683 mini-gmp/tests/t-powm.c
--- a/mini-gmp/tests/t-powm.c	Mon Sep 05 21:05:59 2022 +0200
+++ b/mini-gmp/tests/t-powm.c	Thu Sep 08 22:02:50 2022 +0200
@@ -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 @@
 	  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);


More information about the gmp-commit mailing list