This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[PATCH] Remove unnecessary factorial array
- From: Siddhesh Poyarekar <siddhesh at redhat dot com>
- To: libc-alpha at sourceware dot org
- Date: Wed, 13 Feb 2013 16:43:49 +0530
- Subject: [PATCH] Remove unnecessary factorial array
Hi,
I just realized that in the mpexp fix I just committed, the nfa array
I had created to store factorials of values in the np1 array is
unnecessary. After computation of the following polynomial loop:
double kf = 1.0;
/* Evaluate the rest. The result will be in mpt2. */
for (k = n - 1; k > 0; k--)
{
/* n! / k! = n * (n - 1) ... * (n - k + 1) */
kf *= k + 1;
__dbl_mp (kf, &mpk, p);
__add (&mpt2, &mpk, &mpt1, p);
__mul (&mps, &mpt1, &mpt2, p);
}
kf is in fact n!. Attached patch removes the static variable and uses
kf instead. No regressions observed in the testsuite due to this. OK
to commit?
Siddhesh
* sysdeps/ieee754/dbl-64/mpexp.c (__mpexp): Remove NFA.
diff --git a/sysdeps/ieee754/dbl-64/mpexp.c b/sysdeps/ieee754/dbl-64/mpexp.c
index 2db4536..23432a7 100644
--- a/sysdeps/ieee754/dbl-64/mpexp.c
+++ b/sysdeps/ieee754/dbl-64/mpexp.c
@@ -50,14 +50,6 @@ __mpexp (mp_no *x, mp_no *y, int p)
6, 6, 6, 6, 7, 7, 7, 7, 8, 8, 8, 8, 8
};
- /* Factorials for the values of np above. */
- static const double nfa[33] =
- {
- 1.0, 1.0, 1.0, 1.0, 6.0, 6.0, 24.0, 24.0, 120.0, 24.0, 24.0,
- 120.0, 120.0, 120.0, 720.0, 720.0, 720.0, 720.0, 720.0, 720.0,
- 720.0, 720.0, 720.0, 720.0, 5040.0, 5040.0, 5040.0, 5040.0,
- 40320.0, 40320.0, 40320.0, 40320.0, 40320.0
- };
static const int m1p[33] =
{
0, 0, 0, 0,
@@ -145,7 +137,7 @@ __mpexp (mp_no *x, mp_no *y, int p)
__add (&mpt2, &mpk, &mpt1, p);
__mul (&mps, &mpt1, &mpt2, p);
}
- __dbl_mp (nfa[p], &mpk, p);
+ __dbl_mp (kf, &mpk, p);
__dvd (&mpt2, &mpk, &mpt1, p);
__add (&mpone, &mpt1, &mpt2, p);