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