source: trunk/libs/newlib/src/newlib/libm/math/s_tan.c @ 543

Last change on this file since 543 was 444, checked in by satin@…, 6 years ago

add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc

File size: 2.3 KB
Line 
1
2/* @(#)s_tan.c 5.1 93/09/24 */
3/*
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 *
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
10 * is preserved.
11 * ====================================================
12 */
13
14
15/*
16
17FUNCTION
18        <<tan>>, <<tanf>>---tangent
19
20INDEX
21tan
22INDEX
23tanf
24
25SYNOPSIS
26        #include <math.h>
27        double tan(double <[x]>);
28        float tanf(float <[x]>);
29
30DESCRIPTION
31<<tan>> computes the tangent of the argument <[x]>. 
32Angles are specified in radians. 
33
34<<tanf>> is identical, save that it takes and returns <<float>> values.
35
36RETURNS
37The tangent of <[x]> is returned.
38
39PORTABILITY
40<<tan>> is ANSI. <<tanf>> is an extension.
41*/
42
43/* tan(x)
44 * Return tangent function of x.
45 *
46 * kernel function:
47 *      __kernel_tan            ... tangent function on [-pi/4,pi/4]
48 *      __ieee754_rem_pio2      ... argument reduction routine
49 *
50 * Method.
51 *      Let S,C and T denote the sin, cos and tan respectively on
52 *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
53 *      in [-pi/4 , +pi/4], and let n = k mod 4.
54 *      We have
55 *
56 *          n        sin(x)      cos(x)        tan(x)
57 *     ----------------------------------------------------------
58 *          0          S           C             T
59 *          1          C          -S            -1/T
60 *          2         -S          -C             T
61 *          3         -C           S            -1/T
62 *     ----------------------------------------------------------
63 *
64 * Special cases:
65 *      Let trig be any of sin, cos, or tan.
66 *      trig(+-INF)  is NaN, with signals;
67 *      trig(NaN)    is that NaN;
68 *
69 * Accuracy:
70 *      TRIG(x) returns trig(x) nearly rounded
71 */
72
73#include "fdlibm.h"
74
75#ifndef _DOUBLE_IS_32BITS
76
77#ifdef __STDC__
78        double tan(double x)
79#else
80        double tan(x)
81        double x;
82#endif
83{
84        double y[2],z=0.0;
85        __int32_t n,ix;
86
87    /* High word of x. */
88        GET_HIGH_WORD(ix,x);
89
90    /* |x| ~< pi/4 */
91        ix &= 0x7fffffff;
92        if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
93
94    /* tan(Inf or NaN) is NaN */
95        else if (ix>=0x7ff00000) return x-x;            /* NaN */
96
97    /* argument reduction needed */
98        else {
99            n = __ieee754_rem_pio2(x,y);
100            return __kernel_tan(y[0],y[1],1-((n&1)<<1)); /*   1 -- n even
101                                                        -1 -- n odd */
102        }
103}
104
105#endif /* _DOUBLE_IS_32BITS */
Note: See TracBrowser for help on using the repository browser.