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