From dbcd5a39702fa91d757d412e422a945ed079ec35 Mon Sep 17 00:00:00 2001 From: Marco Bodrato Date: Thu, 8 Sep 2022 22:02:50 +0200 Subject: mini-gmp/tests/t-powm.c: Test some corner cases --- mini-gmp/ChangeLog | 5 +++++ mini-gmp/mini-gmp.c | 3 ++- mini-gmp/tests/t-powm.c | 28 +++++++++++++++++++++++++++- 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 + + * tests/t-powm.c: Test some corner cases (e.g. 1^0 mod 1). + 2022-09-05 Niels Möller * mini-gmp.c (mpz_powm): Fix case of x^0 (mod 1), should be 0. Reported by Guido Vranken. 2022-05-29 Marco Bodrato + * mini-mpq.c (mpq_helper_2exp): New helper (internal) function. 2022-04-18 Niels Möller 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); -- cgit v1.2.1