Inconsistent string conversions

Austyn Krutsinger akrutsinger at gmail.com
Sun Sep 3 19:23:55 UTC 2017


    Maybe this isn't a bug and there is sound logic behind the
implementation, but there is inconsistency between the two different ways
GMP converts strings to numbers. One method allows white-space and the
 other does not. The documentation doesn't directly contradict itself,
however it does leave ambiguity. mpz_set_str explicitly states that it
allows white-space in strings, and that white-space is simply ignored.
mpz_inp_str explicitly states that it ignores preceding white-space, but
makes no mention that it also ignores white-space trailing the string. The
documentation also doesn't specify that mpz_inp_str will truncate the
string at the first white-space it comes to that is not pre or post-fixed.

/* Assume contents of file fp is "1234   56789" */
mpz_inp_str(a, fp, 10);    /* a = 1234 */

mpz_set_str(a, "1234    56789", 10); /* a = 123456789 */


Cheers,
Austyn


More information about the gmp-discuss mailing list