[Gmp-commit] /var/hg/gmp: 3 new changesets

mercurial at gmplib.org mercurial at gmplib.org
Sun May 29 12:08:43 CEST 2022


details:   /var/hg/gmp/rev/92f0445b55ab
changeset: 18355:92f0445b55ab
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 29 12:05:12 2022 +0200
description:
tests/mpz/t-nextprime.c (run_p): abort() on error.

details:   /var/hg/gmp/rev/7ecb57e1bb82
changeset: 18356:7ecb57e1bb82
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 29 12:06:46 2022 +0200
description:
tests/mpz/t-pprime_p.c (acheck_composites): Check some 2spsp (tx: Jan Feitsma)

details:   /var/hg/gmp/rev/ca222a016773
changeset: 18357:ca222a016773
user:      Marco Bodrato <bodrato at mail.dm.unipi.it>
date:      Sun May 29 12:08:19 2022 +0200
description:
mini-gmp/mini-mpq.c (mpq_helper_2exp): New helper function.

diffstat:

 mini-gmp/mini-mpq.c     |  21 ++++++++++++---------
 tests/mpz/t-nextprime.c |   1 +
 tests/mpz/t-pprime_p.c  |  15 +++++++++++++++
 3 files changed, 28 insertions(+), 9 deletions(-)

diffs (82 lines):

diff -r 30bbb7763064 -r ca222a016773 mini-gmp/mini-mpq.c
--- a/mini-gmp/mini-mpq.c	Sat May 14 20:04:41 2022 +0200
+++ b/mini-gmp/mini-mpq.c	Sun May 29 12:08:19 2022 +0200
@@ -5,7 +5,7 @@
    Acknowledgment: special thanks to Bradley Lucier for his comments
    to the preliminary version of this code.
 
-Copyright 2018-2020 Free Software Foundation, Inc.
+Copyright 2018-2022 Free Software Foundation, Inc.
 
 This file is part of the GNU MP Library.
 
@@ -390,22 +390,25 @@
   mpq_clear (t);
 }
 
+static void
+mpq_helper_2exp (mpz_t rn, mpz_t rd, const mpz_t qn, const mpz_t qd, mp_bitcnt_t e)
+{
+  mp_bitcnt_t z = mpz_scan1 (qd, 0);
+  z = GMP_MIN (z, e);
+  mpz_mul_2exp (rn, qn, e - z);
+  mpz_tdiv_q_2exp (rd, qd, z);
+}
+
 void
 mpq_div_2exp (mpq_t r, const mpq_t q, mp_bitcnt_t e)
 {
-  mp_bitcnt_t z = mpz_scan1 (mpq_numref (q), 0);
-  z = GMP_MIN (z, e);
-  mpz_mul_2exp (mpq_denref (r), mpq_denref (q), e - z);
-  mpz_tdiv_q_2exp (mpq_numref (r), mpq_numref (q), z);
+  mpq_helper_2exp (mpq_denref (r), mpq_numref (r), mpq_denref (q), mpq_numref (q), e);
 }
 
 void
 mpq_mul_2exp (mpq_t r, const mpq_t q, mp_bitcnt_t e)
 {
-  mp_bitcnt_t z = mpz_scan1 (mpq_denref (q), 0);
-  z = GMP_MIN (z, e);
-  mpz_mul_2exp (mpq_numref (r), mpq_numref (q), e - z);
-  mpz_tdiv_q_2exp (mpq_denref (r), mpq_denref (q), z);
+  mpq_helper_2exp (mpq_numref (r), mpq_denref (r), mpq_numref (q), mpq_denref (q), e);
 }
 
 void
diff -r 30bbb7763064 -r ca222a016773 tests/mpz/t-nextprime.c
--- a/tests/mpz/t-nextprime.c	Sat May 14 20:04:41 2022 +0200
+++ b/tests/mpz/t-nextprime.c	Sun May 29 12:08:19 2022 +0200
@@ -209,6 +209,7 @@
     {
       gmp_printf ("got  %Zd\n", x);
       gmp_printf ("want %Zd\n", y);
+      abort ();
     }
 
   mpz_clear (y);
diff -r 30bbb7763064 -r ca222a016773 tests/mpz/t-pprime_p.c
--- a/tests/mpz/t-pprime_p.c	Sat May 14 20:04:41 2022 +0200
+++ b/tests/mpz/t-pprime_p.c	Sun May 29 12:08:19 2022 +0200
@@ -104,6 +104,21 @@
   mpz_init (n);
   mpz_init (bs);
 
+  static const char * const composites[] = {
+    "1194649",	/* A square, but strong base-2 pseudoprime,	*/
+    "12327121",	/* another base-2 pseudoprime square.	*/
+    "18446744066047760377",	/* Should trigger Fibonacci's test,	*/
+    "1397419",			/* Lucas' test with "large" D=43,	*/
+    "395009109077493751",	/* Lucas' test with large D=113.	*/
+    NULL
+  };
+
+  for (i = 0; composites[i]; i++)
+    {
+      mpz_set_str_or_abort (n, composites[i], 0);
+      check_one (n, 0);
+    }
+
   for (i = 0; i < count; i++)
     {
       mpz_urandomb (bs, rands, 32);


More information about the gmp-commit mailing list