mini-gmp: add mpz_inp_str functionality

Austyn Krutsinger akrutsinger at gmail.com
Sun Aug 27 19:35:09 UTC 2017


    mini-gmp lacks the mpz_inp_str functionality to import strings from a
file. I've brought this up before, but I failed to providing any decent
solution or test cases. I hope this time, I can provide something
beneficial to the project.
    Attached are possible patches that add the functionality and tests. Up
front, I think it makes the most sense to implement patches 0004 and 0002
and not implementing 0003 or changing patch 0003 to work with patch 0004.
Confusing, I know, but let me explain:


*0001-Add-mpz_inp_str-to-mini-gmp*
    The edited mini-gmp.c and .h that has mpz_inp_str added. One problem(?)
that I ran into is that in order to make the mpz_inp_str function work for
the test cases (both mini-gmp's t-str.c and main GMP's mpz/t-inp_str.c) I
have to read in the string until End Of File or a white-space. The GMP
documentation isn't explicit whether mpz_inp_str allows white-spaces within
the string or not. The documentation only specifies preceding white-spaces:
"Input a possibly white-space preceded string in base base from stdio
stream stream, and put the read integer in rop."[1]

    In contrast mpz_set_str explicitly states it allows white-spaces within
the string itself: "...White space is allowed in the string and is simply
ignored."[2]

    To me, it makes the most sense to allow mpz_inp_str to read in
white-spaces to keep the compatibility with the documented mpz_set_str
function, which is what patch 0004 does.

*0002-Add-mpz_inp_str-to-mini-gmp-s-t-str-tests*
    This is just the addition of mpz_inp_str test in with the same random
strings that are used to test mpz_set_str and mpz_out_str.

*0003-Add-t-inp_str-test-to-mini-gmp-to-mirror-main-GMP-tests*
    This is the replication of the main GMP mpz_inp_str tests.

*0004-Change-mini-gmp-mpz_inp_str-to-allow-white-spaces*
    Recommended mini-gmp change. This correctly converts the numbers and it
passes the tests implemented in t-str from patch 0002 above, however this
will cause the t-inp_str tests recreated from the main GMP to fail, unless
otherwise modified specifically for mini-gmp. To be clear, I mean modifying
mini-gmp's version of t-inp_str test. Nothing within the main GMP is
changed.


Cheers,
Austyn

[1]:
https://gmplib.org/manual/I_002fO-of-Integers.html#index-mpz_005finp_005fstr
[2]:
https://gmplib.org/manual/Assigning-Integers.html#index-mpz_005fset_005fstr
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Add-mpz_inp_str-to-mini-gmp.patch
Type: application/octet-stream
Size: 2484 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20170827/ce1710da/attachment.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0002-Add-mpz_inp_str-to-mini-gmp-s-t-str-tests.patch
Type: application/octet-stream
Size: 1551 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20170827/ce1710da/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0003-Add-t-inp_str-test-to-mini-gmp-to-mirror-main-GMP-te.patch
Type: application/octet-stream
Size: 6305 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20170827/ce1710da/attachment-0002.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0004-Change-mini-gmp-mpz_inp_str-to-allow-white-spaces.patch
Type: application/octet-stream
Size: 692 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-devel/attachments/20170827/ce1710da/attachment-0003.obj>


More information about the gmp-devel mailing list