X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Facosl.c;h=634c247dd658c8717b0c99f39794c494ba706ce0;hb=bbfcd2f1a92c9bdbb8d7d7d0a8a8c6665c316747;hp=bd07e532528e278199c8e4420f9ec900b6561522;hpb=f7b2e38dd51606dab99c4c7f6a456e93efd13591;p=gnulib.git diff --git a/lib/acosl.c b/lib/acosl.c index bd07e5325..634c247dd 100644 --- a/lib/acosl.c +++ b/lib/acosl.c @@ -9,7 +9,23 @@ * ==================================================== */ -#include "mathl.h" +#include + +/* Specification. */ +#include + +#if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE + +long double +acosl (long double x) +{ + return acos (x); +} + +#else + +/* Code based on glibc/sysdeps/ieee754/ldbl-128/e_asinl.c + and glibc/sysdeps/ieee754/ldbl-128/e_acosl.c. */ /* Long double expansions contributed by @@ -18,23 +34,21 @@ /* asin(x) * Method : - * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... - * we approximate asin(x) on [0,0.5] by - * asin(x) = x + x*x^2*R(x^2) + * Since asin(x) = x + x^3/6 + x^5*3/40 + x^7*15/336 + ... + * we approximate asin(x) on [0,0.5] by + * asin(x) = x + x*x^2*R(x^2) * Between .5 and .625 the approximation is * asin(0.5625 + x) = asin(0.5625) + x rS(x) / sS(x) - * For x in [0.625,1] - * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) + * For x in [0.625,1] + * asin(x) = pi/2-2*asin(sqrt((1-x)/2)) * * Special cases: - * if x is NaN, return x itself; - * if |x|>1, return NaN with invalid signal. + * if x is NaN, return x itself; + * if |x|>1, return NaN with invalid signal. * */ -#include - static const long double one = 1.0L, huge = 1.0e+4932L, @@ -43,7 +57,7 @@ static const long double pio2_lo = 4.3359050650618905123985220130216759843812E-35L, pio4_hi = 7.8539816339744830961566084581987569936977E-1L, - /* coefficient for R(x^2) */ + /* coefficient for R(x^2) */ /* asin(x) = x + x^3 pS(x^2) / qS(x^2) 0 <= x <= 0.5 @@ -107,24 +121,24 @@ acosl (long double x) if (x < 0.0L) { - t = pi - acosl(-x); + t = pi - acosl (-x); if (huge + x > one) /* return with inexact */ return t; } - if (x >= 1.0L) /* |x|>= 1 */ + if (x >= 1.0L) /* |x|>= 1 */ { if (x == 1.0L) - return 0.0L; /* return zero */ + return 0.0L; /* return zero */ - return (x - x) / (x - x); /* asin(|x|>1) is NaN */ + return (x - x) / (x - x); /* asin(|x|>1) is NaN */ } else if (x < 0.5L) /* |x| < 0.5 */ { if (x < 0.000000000000000006938893903907228377647697925567626953125L) /* |x| < 2**-57 */ - /* acos(0)=+-pi/2 with inexact */ - return x * pio2_hi + x * pio2_lo; + /* acos(0)=+-pi/2 with inexact */ + return x * pio2_hi + x * pio2_lo; t = x * x; p = (((((((((pS9 * t @@ -156,69 +170,71 @@ acosl (long double x) { t = x - 0.5625; p = ((((((((((rS10 * t - + rS9) * t - + rS8) * t - + rS7) * t - + rS6) * t - + rS5) * t - + rS4) * t - + rS3) * t - + rS2) * t - + rS1) * t - + rS0) * t; + + rS9) * t + + rS8) * t + + rS7) * t + + rS6) * t + + rS5) * t + + rS4) * t + + rS3) * t + + rS2) * t + + rS1) * t + + rS0) * t; q = ((((((((( t - + sS9) * t - + sS8) * t - + sS7) * t - + sS6) * t - + sS5) * t - + sS4) * t - + sS3) * t - + sS2) * t - + sS1) * t - + sS0; + + sS9) * t + + sS8) * t + + sS7) * t + + sS6) * t + + sS5) * t + + sS4) * t + + sS3) * t + + sS2) * t + + sS1) * t + + sS0; return (pio2_hi - asinr5625) - (p / q - pio2_lo); } else - return 2 * asinl(sqrtl((1-x)/2)); + return 2 * asinl (sqrtl ((1 - x) / 2)); } +#endif + #if 0 int main (void) { printf ("%.18Lg %.18Lg\n", - acosl(1.0L), + acosl (1.0L), 1.5707963267948966192313216916397514420984L - 1.5707963267948966192313216916397514420984L); printf ("%.18Lg %.18Lg\n", - acosl(0.7071067811865475244008443621048490392848L), + acosl (0.7071067811865475244008443621048490392848L), 1.5707963267948966192313216916397514420984L - 0.7853981633974483096156608458198757210492L); printf ("%.18Lg %.18Lg\n", - acosl(0.5L), + acosl (0.5L), 1.5707963267948966192313216916397514420984L - 0.5235987755982988730771072305465838140328L); printf ("%.18Lg %.18Lg\n", - acosl(0.3090169943749474241022934171828190588600L), + acosl (0.3090169943749474241022934171828190588600L), 1.5707963267948966192313216916397514420984L - 0.3141592653589793238462643383279502884196L); printf ("%.18Lg %.18Lg\n", - acosl(-1.0L), + acosl (-1.0L), 1.5707963267948966192313216916397514420984L - -1.5707963267948966192313216916397514420984L); printf ("%.18Lg %.18Lg\n", - acosl(-0.7071067811865475244008443621048490392848L), + acosl (-0.7071067811865475244008443621048490392848L), 1.5707963267948966192313216916397514420984L - -0.7853981633974483096156608458198757210492L); printf ("%.18Lg %.18Lg\n", - acosl(-0.5L), + acosl (-0.5L), 1.5707963267948966192313216916397514420984L - -0.5235987755982988730771072305465838140328L); printf ("%.18Lg %.18Lg\n", - acosl(-0.3090169943749474241022934171828190588600L), + acosl (-0.3090169943749474241022934171828190588600L), 1.5707963267948966192313216916397514420984L - -0.3141592653589793238462643383279502884196L); }