1 /* origin: FreeBSD /usr/src/lib/msun/src/s_cos.c */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
13 * Return cosine function of x.
16 * __sin ... sine function on [-pi/4,pi/4]
17 * __cos ... cosine function on [-pi/4,pi/4]
18 * __rem_pio2 ... argument reduction routine
21 * Let S,C and T denote the sin, cos and tan respectively on
22 * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
23 * in [-pi/4 , +pi/4], and let n = k mod 4.
26 * n sin(x) cos(x) tan(x)
27 * ----------------------------------------------------------
32 * ----------------------------------------------------------
35 * Let trig be any of sin, cos, or tan.
36 * trig(+-INF) is NaN, with signals;
37 * trig(NaN) is that NaN;
40 * TRIG(x) returns trig(x) nearly rounded
55 if (ix <= 0x3fe921fb) {
56 if (ix < 0x3e46a09e) { /* |x| < 2**-27 * sqrt(2) */
57 /* raise inexact if x!=0 */
58 FORCE_EVAL(x + 0x1p120f);
64 /* cos(Inf or NaN) is NaN */
68 /* argument reduction */
71 case 0: return __cos(y[0], y[1]);
72 case 1: return -__sin(y[0], y[1], 1);
73 case 2: return -__cos(y[0], y[1]);
75 return __sin(y[0], y[1], 1);