[Gmp-commit] /var/hg/gmp: mini-gmp: Stricter test of mpz_sizeinbase when base...

mercurial at gmplib.org mercurial at gmplib.org
Thu Oct 15 20:32:55 CEST 2026


details:   /var/hg/gmp/rev/c7c1599dfe24
changeset: 18592:c7c1599dfe24
user:      Niels Möller <nisse at lysator.liu.se>
date:      Thu Oct 15 20:32:48 2026 +0200
description:
mini-gmp: Stricter test of mpz_sizeinbase when base is a power of two.

diffstat:

 mini-gmp/ChangeLog     |  5 +++++
 mini-gmp/tests/t-str.c |  4 +++-
 2 files changed, 8 insertions(+), 1 deletions(-)

diffs (33 lines):

diff -r 33db65e2da2e -r c7c1599dfe24 mini-gmp/ChangeLog
--- a/mini-gmp/ChangeLog	Thu Oct 08 22:56:44 2026 +0200
+++ b/mini-gmp/ChangeLog	Thu Oct 15 20:32:48 2026 +0200
@@ -1,3 +1,8 @@
+2026-10-15  Niels Möller  <nisse at lysator.liu.se>
+
+	* tests/t-str.c (testmain): Check that mpz_sizeinbase gives exact
+	result when base is a power of two.
+
 2026-10-08  Niels Möller  <nisse at lysator.liu.se>
 
 	From Pádraig Brady:
diff -r 33db65e2da2e -r c7c1599dfe24 mini-gmp/tests/t-str.c
--- a/mini-gmp/tests/t-str.c	Thu Oct 08 22:56:44 2026 +0200
+++ b/mini-gmp/tests/t-str.c	Thu Oct 15 20:32:48 2026 +0200
@@ -173,6 +173,8 @@
       int base;
       for (base = 0; base <= 62; base += 1 + (base == 0))
 	{
+	  int power_of_two = (base > 0 && (base & (base - 1) == 0));
+
 	  hex_random_str_op (MAXBITS, (i&1 || base > 36) ? base: -base, &ap, &rp);
 	  if (mpz_set_str (a, ap, 16) != 0)
 	    {
@@ -184,7 +186,7 @@
 	  arn = rn - (rp[0] == '-');
 
 	  bn = mpz_sizeinbase (a, base ? base : 10);
-	  if (bn < arn || bn > (arn + 1))
+	  if (bn < arn || bn > (arn + !power_of_two))
 	    {
 	      fprintf (stderr, "mpz_sizeinbase failed:\n");
 	      dump ("a", a);


More information about the gmp-commit mailing list