Re: Efficiency of math.h

From: E. Robert Tisdale (E.Robert.Tisdale_at_jpl.nasa.gov)
Date: 02/26/04


Date: Wed, 25 Feb 2004 15:31:28 -0800

Christian Bau wrote:

> The fastest approach would be to split the argument range into two
> parts, abs(x) <= c and abs(x) >= c for some suitably chosen c,
> probably somewhere around 0.7 or 0.8. For abs (x) <= c, approximate acos
> x by a polynomial of the form (pi - ax - bx^3 - cx^5...). For x > c,
> define f(z) = acos(1 - z^2). Approximate f(z) by a polynomial of the
> form ax + bx^3 + cx^5 + dx^7. Calculate acos(x) = f(sqrt(1 - x)).
> For x < -c use acos(x) = pi() - acos(-x) = pi() - f(sqrt(1 + x)).
> Take a higher polynomial depending on how much precision you want.
> Finding the coefficients is left as an exercise to the reader :)
>
> The substitution z = sqrt(1-x) nicely catches the behavior of acos x
> for abs(x) close to 1, where the first derivative is unbounded
> and avoids excessive rounding errors.

Have you every implemented and tested this "algorithm"?
If so please publish it here so that we can "benchmark" it
against our C library implementations of acos. I'll bet you $1.00 that
I can find one that beats your implementation.