~ubuntu-branches/ubuntu/trusty/monodevelop/trusty-proposed

« back to all changes in this revision

Viewing changes to external/ikvm/runtime/fdlibm/s_tan.cs

  • Committer: Package Import Robot
  • Author(s): Jo Shields
  • Date: 2013-05-12 09:46:03 UTC
  • mto: This revision was merged to the branch mainline in revision 29.
  • Revision ID: package-import@ubuntu.com-20130512094603-mad323bzcxvmcam0
Tags: upstream-4.0.5+dfsg
ImportĀ upstreamĀ versionĀ 4.0.5+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
/*
 
4
 * Copyright (c) 1998, 2001, Oracle and/or its affiliates. All rights reserved.
 
5
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 
6
 *
 
7
 * This code is free software; you can redistribute it and/or modify it
 
8
 * under the terms of the GNU General Public License version 2 only, as
 
9
 * published by the Free Software Foundation.  Oracle designates this
 
10
 * particular file as subject to the "Classpath" exception as provided
 
11
 * by Oracle in the LICENSE file that accompanied this code.
 
12
 *
 
13
 * This code is distributed in the hope that it will be useful, but WITHOUT
 
14
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 
15
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 
16
 * version 2 for more details (a copy is included in the LICENSE file that
 
17
 * accompanied this code).
 
18
 *
 
19
 * You should have received a copy of the GNU General Public License version
 
20
 * 2 along with this work; if not, write to the Free Software Foundation,
 
21
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 
22
 *
 
23
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 
24
 * or visit www.oracle.com if you need additional information or have any
 
25
 * questions.
 
26
 */
 
27
 
 
28
/* tan(x)
 
29
 * Return tangent function of x.
 
30
 *
 
31
 * kernel function:
 
32
 *      __kernel_tan            ... tangent function on [-pi/4,pi/4]
 
33
 *      __ieee754_rem_pio2      ... argument reduction routine
 
34
 *
 
35
 * Method.
 
36
 *      Let S,C and T denote the sin, cos and tan respectively on
 
37
 *      [-PI/4, +PI/4]. Reduce the argument x to y1+y2 = x-k*pi/2
 
38
 *      in [-pi/4 , +pi/4], and let n = k mod 4.
 
39
 *      We have
 
40
 *
 
41
 *          n        sin(x)      cos(x)        tan(x)
 
42
 *     ----------------------------------------------------------
 
43
 *          0          S           C             T
 
44
 *          1          C          -S            -1/T
 
45
 *          2         -S          -C             T
 
46
 *          3         -C           S            -1/T
 
47
 *     ----------------------------------------------------------
 
48
 *
 
49
 * Special cases:
 
50
 *      Let trig be any of sin, cos, or tan.
 
51
 *      trig(+-INF)  is NaN, with signals;
 
52
 *      trig(NaN)    is that NaN;
 
53
 *
 
54
 * Accuracy:
 
55
 *      TRIG(x) returns trig(x) nearly rounded
 
56
 */
 
57
 
 
58
static partial class fdlibm
 
59
{
 
60
        internal static
 
61
        double tan(double x)
 
62
{
 
63
        double z=0.0;
 
64
        int n, ix;
 
65
 
 
66
    /* High word of x. */
 
67
        ix = __HI(x);
 
68
 
 
69
    /* |x| ~< pi/4 */
 
70
        ix &= 0x7fffffff;
 
71
        if(ix <= 0x3fe921fb) return __kernel_tan(x,z,1);
 
72
 
 
73
    /* tan(Inf or NaN) is NaN */
 
74
        else if (ix>=0x7ff00000) return x-x;            /* NaN */
 
75
 
 
76
    /* argument reduction needed */
 
77
        else {
 
78
                        double y_0_ = 0.0, y_1_ = 0.0;
 
79
                        n = __ieee754_rem_pio2(x, ref y_0_, ref y_1_);
 
80
            return __kernel_tan(y_0_,y_1_,1-((n&1)<<1)); /*   1 -- n even
 
81
                                                        -1 -- n odd */
 
82
        }
 
83
    }
 
84
}