xref: /openbsd-src/lib/libm/src/ld128/k_cosl.c (revision 390c8400525fc0ecc9e2c49c2246076b1b49fe19)
1*390c8400Smartynas /*	$OpenBSD: k_cosl.c,v 1.1 2008/12/09 20:00:35 martynas Exp $	*/
2*390c8400Smartynas /* From: @(#)k_cos.c 1.3 95/01/18 */
3*390c8400Smartynas /*
4*390c8400Smartynas  * ====================================================
5*390c8400Smartynas  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6*390c8400Smartynas  * Copyright (c) 2008 Steven G. Kargl, David Schultz, Bruce D. Evans.
7*390c8400Smartynas  *
8*390c8400Smartynas  * Developed at SunSoft, a Sun Microsystems, Inc. business.
9*390c8400Smartynas  * Permission to use, copy, modify, and distribute this
10*390c8400Smartynas  * software is freely granted, provided that this notice
11*390c8400Smartynas  * is preserved.
12*390c8400Smartynas  * ====================================================
13*390c8400Smartynas  */
14*390c8400Smartynas 
15*390c8400Smartynas /*
16*390c8400Smartynas  * ld128 version of k_cos.c.  See ../k_cos.c for most comments.
17*390c8400Smartynas  */
18*390c8400Smartynas 
19*390c8400Smartynas #include "math_private.h"
20*390c8400Smartynas 
21*390c8400Smartynas /*
22*390c8400Smartynas  * Domain [-0.7854, 0.7854], range ~[-1.80e-37, 1.79e-37]:
23*390c8400Smartynas  * |cos(x) - c(x))| < 2**-122.0
24*390c8400Smartynas  *
25*390c8400Smartynas  * 113-bit precision requires more care than 64-bit precision, since
26*390c8400Smartynas  * simple methods give a minimax polynomial with coefficient for x^2
27*390c8400Smartynas  * that is 1 ulp below 0.5, but we want it to be precisely 0.5.  See
28*390c8400Smartynas  * ../ld80/k_cosl.c for more details.
29*390c8400Smartynas  */
30*390c8400Smartynas static const double
31*390c8400Smartynas one = 1.0;
32*390c8400Smartynas 
33*390c8400Smartynas static const long double
34*390c8400Smartynas C1 =  0.04166666666666666666666666666666658424671L,
35*390c8400Smartynas C2 = -0.001388888888888888888888888888863490893732L,
36*390c8400Smartynas C3 =  0.00002480158730158730158730158600795304914210L,
37*390c8400Smartynas C4 = -0.2755731922398589065255474947078934284324e-6L,
38*390c8400Smartynas C5 =  0.2087675698786809897659225313136400793948e-8L,
39*390c8400Smartynas C6 = -0.1147074559772972315817149986812031204775e-10L,
40*390c8400Smartynas C7 =  0.4779477332386808976875457937252120293400e-13L;
41*390c8400Smartynas 
42*390c8400Smartynas static const double
43*390c8400Smartynas C8 = -0.1561920696721507929516718307820958119868e-15,
44*390c8400Smartynas C9 =  0.4110317413744594971475941557607804508039e-18,
45*390c8400Smartynas C10 = -0.8896592467191938803288521958313920156409e-21,
46*390c8400Smartynas C11 =  0.1601061435794535138244346256065192782581e-23;
47*390c8400Smartynas 
48*390c8400Smartynas long double
__kernel_cosl(long double x,long double y)49*390c8400Smartynas __kernel_cosl(long double x, long double y)
50*390c8400Smartynas {
51*390c8400Smartynas 	long double hz,z,r,w;
52*390c8400Smartynas 
53*390c8400Smartynas 	z  = x*x;
54*390c8400Smartynas 	r  = z*(C1+z*(C2+z*(C3+z*(C4+z*(C5+z*(C6+z*(C7+
55*390c8400Smartynas 	    z*(C8+z*(C9+z*(C10+z*C11))))))))));
56*390c8400Smartynas 	hz = 0.5*z;
57*390c8400Smartynas 	w  = one-hz;
58*390c8400Smartynas 	return w + (((one-w)-hz) + (z*r-x*y));
59*390c8400Smartynas }
60