1176358Sdas/* From: @(#)k_cos.c 1.3 95/01/18 */
2176358Sdas/*
3176358Sdas * ====================================================
4176358Sdas * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
5176358Sdas * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
6176358Sdas *
7176358Sdas * Developed at SunSoft, a Sun Microsystems, Inc. business.
8176358Sdas * Permission to use, copy, modify, and distribute this
9176358Sdas * software is freely granted, provided that this notice
10176358Sdas * is preserved.
11176358Sdas * ====================================================
12176358Sdas */
13176358Sdas
14176358Sdas#include <sys/cdefs.h>
15176358Sdas__FBSDID("$FreeBSD$");
16176358Sdas
17176358Sdas/*
18176358Sdas * ld128 version of k_cos.c.  See ../src/k_cos.c for most comments.
19176358Sdas */
20176358Sdas
21176358Sdas#include "math_private.h"
22176358Sdas
23176358Sdas/*
24176358Sdas * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]:
25176358Sdas * |cos(x) - c(x))| < 2**-122.0
26176358Sdas *
27176358Sdas * 113-bit precision requires more care than 64-bit precision, since
28176358Sdas * simple methods give a minimax polynomial with coefficient for x^2
29176358Sdas * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
30176358Sdas * ../ld80/k_cosl.c for more details.
31176358Sdas */
32176358Sdasstatic const double
33176358Sdasone = 1.0;
34176358Sdas
35176358Sdasstatic const long double
36176358SdasC1 =  0.04166666666666666666666666666666658424671L,
37176358SdasC2 = -0.001388888888888888888888888888863490893732L,
38176358SdasC3 =  0.00002480158730158730158730158600795304914210L,
39176358SdasC4 = -0.2755731922398589065255474947078934284324e-6L,
40176358SdasC5 =  0.2087675698786809897659225313136400793948e-8L,
41176358SdasC6 = -0.1147074559772972315817149986812031204775e-10L,
42176358SdasC7 =  0.4779477332386808976875457937252120293400e-13L;
43176358Sdas
44176358Sdasstatic const double
45176358SdasC8 = -0.1561920696721507929516718307820958119868e-15,
46176358SdasC9 =  0.4110317413744594971475941557607804508039e-18,
47176358SdasC10 = -0.8896592467191938803288521958313920156409e-21,
48176358SdasC11 =  0.1601061435794535138244346256065192782581e-23;
49176358Sdas
50176358Sdaslong double
51176358Sdas__kernel_cosl(long double x, long double y)
52176358Sdas{
53176358Sdas	long double hz,z,r,w;
54176358Sdas
55176358Sdas	z  = x*x;
56176358Sdas	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+
57176358Sdas	    z*(C8+z*(C9+z*(C10+z*C11))))))))));
58176358Sdas	hz = 0.5*z;
59176358Sdas	w  = one-hz;
60176358Sdas	return w + (((one-w)-hz) + (z*r-x*y));
61176358Sdas}
62