This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
[RFC] Speedup trig. functions with large inputs.
- From: OndÅej BÃlka <neleai at seznam dot cz>
- To: libc-alpha at sourceware dot org
- Date: Tue, 30 Apr 2013 00:05:47 +0200
- Subject: [RFC] Speedup trig. functions with large inputs.
Hi,
As you want correctly rounding variants of trigionometric functions I
have relatively fast way how do remainder by pi. This reduces domain
where you need to compute them. Main idea is that for double exponent
can have only 1023 positive values.
So we compute table containing (2**i) mod pi for these i and suming them
together gives number that is at most 55*pi large. I could do this in
integers with 64bit precision.
I could add precise division in rare case that result lies on boundary.
Comments?
#include <stdint.h>
uint64_t modpi[1024+52];
double mod_by_pi(double x)
{
int i;
uint64_t mag = MAGNITUDE(x);
uint64_t frac = FRACTIONAL(x);
if (mag <= 0)
return x;
uint64_t sum=0;
for (i = 0 ; i <= 55 ; i++)
sum += modpi[mag+52-i] & (((frac<<i)&(((uint64_t)1)<<63))-1);
if (boundary)
more_precise_division.
return MAKE_DOUBLE(sum);
}