mpfr: remove pregenerated files

This commit is contained in:
fosslinux 2025-03-25 22:12:02 +11:00 committed by Samuel Tyler
parent deb37bb460
commit a7e0cc54ea
No known key found for this signature in database
GPG key ID: EB5091A5C77E8DC4
3 changed files with 62 additions and 6 deletions

View file

@ -5,7 +5,16 @@
src_prepare() {
default
find . -name '*.info' -delete
# Remove pregenerated table in strtofr.c
sed -i '/^ {/,/ };$/d' src/strtofr.c
cp src/strtofr.c{,.old}
sed -i '/int RedInvLog2Table/ s/$/};/' src/strtofr.c
rm doc/*.info
# testfiles
rm tests/tfpif_*.dat tests/tstrtofr.c
AUTOMAKE=automake-1.15 ACLOCAL=aclocal-1.15 autoreconf-2.69 -fi
}
@ -21,6 +30,25 @@ src_configure() {
src_compile() {
make "${MAKEJOBS}" MAKEINFO=true DESTDIR="${DESTDIR}"
pushd src
cat > strtofr_gen.c <<EOF
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>
EOF
# Enable the bit of code that generates the table
sed -n '/^#define N 8$/,/^}$/p' strtofr.c >> strtofr_gen.c
gcc strtofr_gen.c -o strtofr_gen -std=gnu99 -I. -L.libs -lmpfr -lgmp
# ordering of 2>&1 >/dev/null is intentional here;
# stdout -> null
# stderr -> file (NOT null)
./strtofr_gen 2>strtofr_table >/dev/null
echo "};" >> strtofr_table
sed "/int RedInvLog2Table/ r strtofr_table" strtofr.c.old > strtofr.c
popd
make "${MAKEJOBS}" MAKEINFO=true DESTDIR="${DESTDIR}"
}
src_install() {

View file

@ -0,0 +1,28 @@
SPDX-FileCopyrightText: 2025 fosslinux <fosslinux@aussies.space>
SPDX-License-Identifier: GPL-3.0-or-later
The code to generate the table in strtofr.c was written in 2004 and not
updated since. Not sure if this case was ever actually handled.
Without this check, we end up dividing by zero, which creates problematic
results.
To fix this, check if the divisor is zero, and if it is, early exit (and
fill the rest of the continued fraction with zeros).
--- mpfr-4.1.0/src/strtofr.c 2025-10-03 22:15:37.527948986 +1000
+++ mpfr-4.1.0/src/strtofr.c 2025-10-03 22:18:18.480958600 +1000
@@ -136,6 +136,14 @@
mpfr_floor (y, x);
tab[i] = mpfr_get_ui (y, MPFR_RNDN);
mpfr_sub (x, x, y, MPFR_RNDN);
+ if (mpfr_zero_p(x))
+ {
+ for (i++; i < N; i++)
+ {
+ tab[i] = 0;
+ }
+ break;
+ }
mpfr_ui_div (x, 1, x, MPFR_RNDN);
}
for (i = N-1 ; i >= 0 ; i--)