1/* From: @(#)k_cos.c 1.3 95/01/18 */
2/*
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5 * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
6 *
7 * Developed at SunSoft, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14#include <sys/cdefs.h>
15/*
16 * ld128 version of k_cos.c.  See ../src/k_cos.c for most comments.
17 */
18
19#include "math_private.h"
20
21/*
22 * Domain [-0.7854, 0.7854], range ~[-1.17e-39, 1.19e-39]:
23 * |cos(x) - c(x))| < 2**-129.3
24 *
25 * 113-bit precision requires more care than 64-bit precision, since
26 * simple methods give a minimax polynomial with coefficient for x^2
27 * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
28 * ../ld80/k_cosl.c for more details.
29 */
30static const double
31one = 1.0;
32static const long double
33C1 =  4.16666666666666666666666666666666667e-02L,
34C2 = -1.38888888888888888888888888888888834e-03L,
35C3 =  2.48015873015873015873015873015446795e-05L,
36C4 = -2.75573192239858906525573190949988493e-07L,
37C5 =  2.08767569878680989792098886701451072e-09L,
38C6 = -1.14707455977297247136657111139971865e-11L,
39C7 =  4.77947733238738518870113294139830239e-14L,
40C8 = -1.56192069685858079920640872925306403e-16L,
41C9 =  4.11031762320473354032038893429515732e-19L,
42C10= -8.89679121027589608738005163931958096e-22L,
43C11=  1.61171797801314301767074036661901531e-24L,
44C12= -2.46748624357670948912574279501044295e-27L;
45
46long double
47__kernel_cosl(long double x, long double y)
48{
49	long double hz,z,r,w;
50
51	z  = x*x;
52	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+
53	    z*(C8+z*(C9+z*(C10+z*(C11+z*C12)))))))))));
54	hz = 0.5*z;
55	w  = one-hz;
56	return w + (((one-w)-hz) + (z*r-x*y));
57}
58