1 | /* s_cosl.c -- long double version of s_cos.c. |
2 | * Conversion to long double by Ulrich Drepper, |
3 | * Cygnus Support, drepper@cygnus.com. |
4 | */ |
5 | |
6 | /* |
7 | * ==================================================== |
8 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
9 | * |
10 | * Developed at SunPro, a Sun Microsystems, Inc. business. |
11 | * Permission to use, copy, modify, and distribute this |
12 | * software is freely granted, provided that this notice |
13 | * is preserved. |
14 | * ==================================================== |
15 | */ |
16 | |
17 | #if defined(LIBM_SCCS) && !defined(lint) |
18 | static char rcsid[] = "$NetBSD: $" ; |
19 | #endif |
20 | |
21 | /* cosl(x) |
22 | * Return cosine function of x. |
23 | * |
24 | * kernel function: |
25 | * __kernel_sinl ... sine function on [-pi/4,pi/4] |
26 | * __kernel_cosl ... cosine function on [-pi/4,pi/4] |
27 | * __ieee754_rem_pio2l ... argument reduction routine |
28 | * |
29 | * Method. |
30 | * Let S,C and T denote the sin, cos and tan respectively on |
31 | * [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2 |
32 | * in [-pi/4 , +pi/4], and let n = k mod 4. |
33 | * We have |
34 | * |
35 | * n sin(x) cos(x) tan(x) |
36 | * ---------------------------------------------------------- |
37 | * 0 S C T |
38 | * 1 C -S -1/T |
39 | * 2 -S -C T |
40 | * 3 -C S -1/T |
41 | * ---------------------------------------------------------- |
42 | * |
43 | * Special cases: |
44 | * Let trig be any of sin, cos, or tan. |
45 | * trig(+-INF) is NaN, with signals; |
46 | * trig(NaN) is that NaN; |
47 | * |
48 | * Accuracy: |
49 | * TRIG(x) returns trig(x) nearly rounded |
50 | */ |
51 | |
52 | #include <errno.h> |
53 | #include <math.h> |
54 | #include <math_private.h> |
55 | #include <libm-alias-ldouble.h> |
56 | |
57 | long double __cosl(long double x) |
58 | { |
59 | long double y[2],z=0.0; |
60 | int32_t n, se, i0, i1; |
61 | |
62 | /* High word of x. */ |
63 | GET_LDOUBLE_WORDS(se,i0,i1,x); |
64 | |
65 | /* |x| ~< pi/4 */ |
66 | se &= 0x7fff; |
67 | if(se < 0x3ffe || (se == 0x3ffe && i0 <= 0xc90fdaa2)) |
68 | return __kernel_cosl(x,z); |
69 | |
70 | /* cos(Inf or NaN) is NaN */ |
71 | else if (se==0x7fff) { |
72 | if (i1 == 0 && i0 == 0x80000000) |
73 | __set_errno (EDOM); |
74 | return x-x; |
75 | } |
76 | |
77 | /* argument reduction needed */ |
78 | else { |
79 | n = __ieee754_rem_pio2l(x,y); |
80 | switch(n&3) { |
81 | case 0: return __kernel_cosl(y[0],y[1]); |
82 | case 1: return -__kernel_sinl(y[0],y[1],1); |
83 | case 2: return -__kernel_cosl(y[0],y[1]); |
84 | default: |
85 | return __kernel_sinl(y[0],y[1],1); |
86 | } |
87 | } |
88 | } |
89 | libm_alias_ldouble (__cos, cos) |
90 | |