Reduced number of allocated limbs after calling mpz_remove

Niels Möller nisse at lysator.liu.se
Mon May 20 20:58:15 CEST 2024


marco.bodrato at tutanota.com writes:

>> I don't have a strong opinion on how to fix this discrepancy between
>> docs and implementation.
>
> I'll correct the _remove function, it's quite easy to do :-)

Nice! To avoid regressions, it would be good to have tests for this.
Could possibly go in tests/mpz/reuse.c, but looks like a fair amount of
work to do properly.

>> But I feel rather strongly that mini-gmp shouldn't make this promise,
>> so code that rely on it will not work with mini-gmp.
>
> I agree for the mini-gmp side.

Then it should be documented as an exception in mini-gmp/README.
Suggested update below.

Regards,
/Niels

--- a/mini-gmp/README	Wed May 15 20:51:11 2024 +0200
+++ b/mini-gmp/README	Mon May 20 20:53:53 2024 +0200
@@ -39,21 +39,24 @@ mini-gmp as a fallback when for some rea
 not desired as a dependency.
 
 The supported GMP subset of the mpn and mpz interfaces is declared in
-mini-gmp.h, and implemented in mini-gmp.c. The implemented
-functions are fully compatible with the corresponding GMP functions,
-as specified in the GMP manual, with a few exceptions:
+mini-gmp.h, and implemented in mini-gmp.c. The supported GMP subset of
+the mpq layer is declared in mini-mpq.h, and implemented in
+mini-mpq.c. The implemented functions are fully compatible with the
+corresponding GMP functions, as specified in the GMP manual, with a
+few exceptions:
 
   mpz_export and mpz_import support only NAILS = 0.
 
+  mini-gmp's handling of destinations operands does not satisfy the
+  documented property that 'mpz_t' and 'mpq_t' variables never reduce
+  their allocated space.
+
 The performance target for mini-gmp is to be at most 10 times slower
 than the real GMP library, for numbers of size up to a few hundred
 bits. No asymptotically fast algorithms are included in mini-gmp, so
 it will be many orders of magnitude slower than GMP for very large
 numbers.
 
-The supported GMP subset of the mpq layer is declared in mini-mpq.h,
-and implemented in mini-mpq.c.
-
 You should never "install" mini-gmp. Applications can either just
 #include mini-gmp.c (but then, beware that it defines several macros
 and functions outside of the advertised interface), and if needed


-- 
Niels Möller. PGP key CB4962D070D77D7FCB8BA36271D8F1FF368C6677.
Internet email is subject to wholesale government surveillance.


More information about the gmp-bugs mailing list