[RFC] Speedup trig. functions with large inputs.
Ondřej Bílka
neleai@seznam.cz
Tue Apr 30 06:17:00 GMT 2013
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);
}
More information about the Libc-alpha
mailing list