xref: /freebsd-src/lib/msun/ld128/k_cosl.c (revision 0dd5a5603e7a33d976f8e6015620bbc79839c609)
161f95582SDavid Schultz /*
261f95582SDavid Schultz  * ====================================================
361f95582SDavid Schultz  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
461f95582SDavid Schultz  * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
561f95582SDavid Schultz  *
661f95582SDavid Schultz  * Developed at SunSoft, a Sun Microsystems, Inc. business.
761f95582SDavid Schultz  * Permission to use, copy, modify, and distribute this
861f95582SDavid Schultz  * software is freely granted, provided that this notice
961f95582SDavid Schultz  * is preserved.
1061f95582SDavid Schultz  * ====================================================
1161f95582SDavid Schultz  */
1261f95582SDavid Schultz 
1361f95582SDavid Schultz /*
1461f95582SDavid Schultz  * ld128 version of k_cos.c.  See ../src/k_cos.c for most comments.
1561f95582SDavid Schultz  */
1661f95582SDavid Schultz 
1761f95582SDavid Schultz #include "math_private.h"
1861f95582SDavid Schultz 
1961f95582SDavid Schultz /*
20*6d04e142SSteve Kargl  * Domain [-0.7854, 0.7854], range ~[-1.17e-39, 1.19e-39]:
21*6d04e142SSteve Kargl  * |cos(x) - c(x))| < 2**-129.3
2261f95582SDavid Schultz  *
2361f95582SDavid Schultz  * 113-bit precision requires more care than 64-bit precision, since
2461f95582SDavid Schultz  * simple methods give a minimax polynomial with coefficient for x^2
2561f95582SDavid Schultz  * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
2661f95582SDavid Schultz  * ../ld80/k_cosl.c for more details.
2761f95582SDavid Schultz  */
2861f95582SDavid Schultz static const double
2961f95582SDavid Schultz one = 1.0;
3061f95582SDavid Schultz static const long double
31*6d04e142SSteve Kargl C1 =  4.16666666666666666666666666666666667e-02L,
32*6d04e142SSteve Kargl C2 = -1.38888888888888888888888888888888834e-03L,
33*6d04e142SSteve Kargl C3 =  2.48015873015873015873015873015446795e-05L,
34*6d04e142SSteve Kargl C4 = -2.75573192239858906525573190949988493e-07L,
35*6d04e142SSteve Kargl C5 =  2.08767569878680989792098886701451072e-09L,
36*6d04e142SSteve Kargl C6 = -1.14707455977297247136657111139971865e-11L,
37*6d04e142SSteve Kargl C7 =  4.77947733238738518870113294139830239e-14L,
38*6d04e142SSteve Kargl C8 = -1.56192069685858079920640872925306403e-16L,
39*6d04e142SSteve Kargl C9 =  4.11031762320473354032038893429515732e-19L,
40*6d04e142SSteve Kargl C10= -8.89679121027589608738005163931958096e-22L,
41*6d04e142SSteve Kargl C11=  1.61171797801314301767074036661901531e-24L,
42*6d04e142SSteve Kargl C12= -2.46748624357670948912574279501044295e-27L;
4361f95582SDavid Schultz 
4461f95582SDavid Schultz long double
__kernel_cosl(long double x,long double y)4561f95582SDavid Schultz __kernel_cosl(long double x, long double y)
4661f95582SDavid Schultz {
4761f95582SDavid Schultz 	long double hz,z,r,w;
4861f95582SDavid Schultz 
4961f95582SDavid Schultz 	z  = x*x;
5061f95582SDavid Schultz 	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+
51*6d04e142SSteve Kargl 	    z*(C8+z*(C9+z*(C10+z*(C11+z*C12)))))))))));
5261f95582SDavid Schultz 	hz = 0.5*z;
5361f95582SDavid Schultz 	w  = one-hz;
5461f95582SDavid Schultz 	return w + (((one-w)-hz) + (z*r-x*y));
5561f95582SDavid Schultz }
56