1 /* cos (cosine) function with 'long double' argument.
3 Copyright (C) 2003-2024 Free Software Foundation, Inc.
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation, either version 3 of the
8 License, or (at your option) any later version.
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
18 /* s_cosl.c -- long double version of s_sin.c.
19 * Conversion to long double by Jakub Jelinek, jj@ultra.linux.cz.
23 * ====================================================
24 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
26 * Developed at SunPro, a Sun Microsystems, Inc. business.
27 * Permission to use, copy, modify, and distribute this
28 * software is freely granted, provided that this notice
30 * ====================================================
38 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
48 /* Code based on glibc/sysdeps/ieee754/ldbl-128/s_cosl.c. */
51 * Return cosine function of x.
54 * __kernel_sinl ... sine function on [-pi/4,pi/4]
55 * __kernel_cosl ... cosine function on [-pi/4,pi/4]
56 * __ieee754_rem_pio2l ... argument reduction routine
59 * Let S,C and T denote the sin, cos and tan respectively on
60 * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
61 * in [-pi/4 , +pi/4], and let n = k mod 4.
64 * n sin(x) cos(x) tan(x)
65 * ----------------------------------------------------------
70 * ----------------------------------------------------------
73 * Let trig be any of sin, cos, or tan.
74 * trig(+-INF) is NaN, with signals;
75 * trig(NaN) is that NaN;
78 * TRIG(x) returns trig(x) nearly rounded
86 long double y
[2],z
=0.0L;
89 /* cosl(NaN) is NaN */
94 if (x
>= -0.7853981633974483096156608458198757210492
95 && x
<= 0.7853981633974483096156608458198757210492)
96 return kernel_cosl(x
, z
);
98 /* cosl(Inf) is NaN, cosl(0) is 1 */
99 else if (x
+ x
== x
&& x
!= 0.0)
100 return x
- x
; /* NaN */
102 /* argument reduction needed */
105 n
= ieee754_rem_pio2l (x
, y
);
109 return kernel_cosl (y
[0], y
[1]);
111 return -kernel_sinl (y
[0], y
[1], 1);
113 return -kernel_cosl (y
[0], y
[1]);
115 return kernel_sinl (y
[0], y
[1], 1);
126 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492));
127 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *29));
128 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *2));
129 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *30));
130 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *4));
131 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *32));
132 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *2/3));
133 printf ("%.16Lg\n", cosl (0.7853981633974483096156608458198757210492 *4/3));