GMP Bug Report
James Cumberbatch
james.a.cumberbatch at gmail.com
Fri Feb 21 14:00:00 CET 2025
Hello,
Here's a bug report, concerning mpz_inp_raw.
Version number: 6.3.0, also 6.2.1. (Tested it on two computers) 6.3.0
was installed using homebrew (No special options, just "brew install
gmp"), 6.2.1 was not installed by me.
Test program: Attached.
Description of what is wrong: When using mpz_inp_raw to load a number
which is at least 2^(2^34), a different value to the one which is
written is loaded. Arithmetic works fine with these numbers and
doesn't go wrong until larger numbers where gmp doesn't claim to work,
only loading the number from a file goes wrong. (Or theoretically the
error might be in mpz_out_raw, but doing a hexdump it looks like it's
probably correct). mpz_inp_str has a similar issue, though I have done
less testing with that one.
Pseudocode of the attached program:
Initialize mpz_t X and set it to 2^(2^34), write it to a file with
mpz_out_raw, initialize mpz_t X2 and set it using mpz_inp_raw on the
file which was just written, display how many bytes were written and
how many bytes were read, display the result of using mpz_cmp on X and
X2.
Output of the program I get, same on both computers:
Exponentiated
80000005 bits written
80000003 bits read
The sign of X-X2 is the sign of 1.
Expected output:
Exponentiated
80000005 bits written
80000005 bits read
The sign of X-X2 is the sign of 0.
Additionally, while not demonstrated in this program, the number of
bits read shrinks when larger numbers are written. Or at least, when
numbers which are a little bit larger are written, then strange things
happen as you go larger (Only 5 bits are read from 2^(2^35)).
Configure things: I didn't build gmp myself so I don't know. On one
computer I used homebrew, on the other someone else installed gmp.
Outputs of gcc -v and uname -a: Attached.
There's also a similar glitch when using mpz_inp_str, though I haven't
done as much testing with that.
Best,
-------------- next part --------------
Computer 1, the supercomputer running linux and GMP 6.2.1, not installed by me:
Output of uname -a:
Linux login04.negishi.rcac.purdue.edu 4.18.0-553.5.1.el8_10.x86_64 #1 SMP Thu Jun 6 09:41:19 UTC 2024 x86_64 x86_64 x86_64 GNU/Linux
Output of gcc -v:
Reading specs from /apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj/lib/gcc/x86_64-pc-linux-gnu/12.2.0/specs
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj/libexec/gcc/x86_64-pc-linux-gnu/12.2.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /tmp/rcactest/spack-stage-gcc-12.2.0-27t2zcjbehdhtlcxcm7l4tfs5wjlu6wj/spack-src/configure --prefix=/apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj --with-pkgversion='Spack GCC' --with-bugurl=https://github.com/spack/spack/issues --disable-multilib --enable-languages=c,c++,fortran --disable-nls --disable-canonical-system-headers --with-system-zlib --with-zstd-include=/apps/spack/negishi/apps/zstd/1.5.2-gcc-8.5.0-uc4tlul/include --with-zstd-lib=/apps/spack/negishi/apps/zstd/1.5.2-gcc-8.5.0-uc4tlul/lib --enable-bootstrap --with-mpfr-include=/apps/spack/negishi/apps/mpfr/4.0.2-gcc-8.5.0-7c2eh7r/include --with-mpfr-lib=/apps/spack/negishi/apps/mpfr/4.0.2-gcc-8.5.0-7c2eh7r/lib --with-gmp-include=/apps/spack/negishi/apps/gmp/6.2.1-gcc-8.5.0-sh44noy/include --with-gmp-lib=/apps/spack/negishi/apps/gmp/6.2.1-gcc-8.5.0-sh44noy/lib --with-mpc-include=/apps/spack/negishi/apps/mpc/1.1.0-gcc-8.5.0-rmvlya2/include --with-mpc-lib=/apps/spack/negishi/apps/mpc/1.1.0-gcc-8.5.0-rmvlya2/lib --without-isl --with-stage1-ldflags='-Wl,-rpath,/apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj/lib -Wl,-rpath,/apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj/lib64 -Wl,-rpath,/apps/spack/negishi/apps/gmp/6.2.1-gcc-8.5.0-sh44noy/lib -Wl,-rpath,/apps/spack/negishi/apps/mpc/1.1.0-gcc-8.5.0-rmvlya2/lib -Wl,-rpath,/apps/spack/negishi/apps/mpfr/4.0.2-gcc-8.5.0-7c2eh7r/lib -Wl,-rpath,/apps/spack/negishi/apps/zlib/1.2.13-gcc-8.5.0-abs3mss/lib -Wl,-rpath,/apps/spack/negishi/apps/zstd/1.5.2-gcc-8.5.0-uc4tlul/lib' --with-boot-ldflags='-Wl,-rpath,/apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj/lib -Wl,-rpath,/apps/spack/negishi/apps/gcc/12.2.0-gcc-8.5.0-27t2zcj/lib64 -Wl,-rpath,/apps/spack/negishi/apps/gmp/6.2.1-gcc-8.5.0-sh44noy/lib -Wl,-rpath,/apps/spack/negishi/apps/mpc/1.1.0-gcc-8.5.0-rmvlya2/lib -Wl,-rpath,/apps/spack/negishi/apps/mpfr/4.0.2-gcc-8.5.0-7c2eh7r/lib -Wl,-rpath,/apps/spack/negishi/apps/zlib/1.2.13-gcc-8.5.0-abs3mss/lib -Wl,-rpath,/apps/spack/negishi/apps/zstd/1.5.2-gcc-8.5.0-uc4tlul/lib -static-libstdc++ -static-libgcc' --with-build-config=spack
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 12.2.0 (Spack GCC)
Computer 2, M1 Macbook Air running GMP 6.3.0, installed using homebrew:
Output of uname -a:
Darwin pal-nat186-106-127.itap.purdue.edu 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:34 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T8103 arm64
Output of gcc -v:
Apple clang version 15.0.0 (clang-1500.1.0.2.5)
Target: arm64-apple-darwin23.2.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
-------------- next part --------------
A non-text attachment was scrubbed...
Name: gmpsimpbug.c
Type: text/x-c-code
Size: 554 bytes
Desc: not available
URL: <https://gmplib.org/list-archives/gmp-bugs/attachments/20250221/b1814c40/attachment.bin>
More information about the gmp-bugs
mailing list