~ubuntu-branches/ubuntu/karmic/python-scipy/karmic

« back to all changes in this revision

Viewing changes to Lib/special/cephes/tandg.c

  • Committer: Bazaar Package Importer
  • Author(s): Ondrej Certik
  • Date: 2008-06-16 22:58:01 UTC
  • mfrom: (2.1.24 intrepid)
  • Revision ID: james.westby@ubuntu.com-20080616225801-irdhrpcwiocfbcmt
Tags: 0.6.0-12
* The description updated to match the current SciPy (Closes: #489149).
* Standards-Version bumped to 3.8.0 (no action needed)
* Build-Depends: netcdf-dev changed to libnetcdf-dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*                                                      tandg.c
2
 
 *
3
 
 *      Circular tangent of argument in degrees
4
 
 *
5
 
 *
6
 
 *
7
 
 * SYNOPSIS:
8
 
 *
9
 
 * double x, y, tandg();
10
 
 *
11
 
 * y = tandg( x );
12
 
 *
13
 
 *
14
 
 *
15
 
 * DESCRIPTION:
16
 
 *
17
 
 * Returns the circular tangent of the argument x in degrees.
18
 
 *
19
 
 * Range reduction is modulo pi/4.  A rational function
20
 
 *       x + x**3 P(x**2)/Q(x**2)
21
 
 * is employed in the basic interval [0, pi/4].
22
 
 *
23
 
 *
24
 
 *
25
 
 * ACCURACY:
26
 
 *
27
 
 *                      Relative error:
28
 
 * arithmetic   domain     # trials      peak         rms
29
 
 *    DEC      0,10          8000      3.4e-17      1.2e-17
30
 
 *    IEEE     0,10         30000      3.2e-16      8.4e-17
31
 
 *
32
 
 * ERROR MESSAGES:
33
 
 *
34
 
 *   message         condition          value returned
35
 
 * tandg total loss   x > 8.0e14 (DEC)      0.0
36
 
 *                    x > 1.0e14 (IEEE)
37
 
 * tandg singularity  x = 180 k  +  90     MAXNUM
38
 
 */
39
 
/*                                                     cotdg.c
40
 
 *
41
 
 *      Circular cotangent of argument in degrees
42
 
 *
43
 
 *
44
 
 *
45
 
 * SYNOPSIS:
46
 
 *
47
 
 * double x, y, cotdg();
48
 
 *
49
 
 * y = cotdg( x );
50
 
 *
51
 
 *
52
 
 *
53
 
 * DESCRIPTION:
54
 
 *
55
 
 * Returns the circular cotangent of the argument x in degrees.
56
 
 *
57
 
 * Range reduction is modulo pi/4.  A rational function
58
 
 *       x + x**3 P(x**2)/Q(x**2)
59
 
 * is employed in the basic interval [0, pi/4].
60
 
 *
61
 
 *
62
 
 * ERROR MESSAGES:
63
 
 *
64
 
 *   message         condition          value returned
65
 
 * cotdg total loss   x > 8.0e14 (DEC)      0.0
66
 
 *                    x > 1.0e14 (IEEE)
67
 
 * cotdg singularity  x = 180 k            MAXNUM
68
 
 */
69
 
 
70
 
/*
71
 
Cephes Math Library Release 2.0:  April, 1987
72
 
Copyright 1984, 1987 by Stephen L. Moshier
73
 
Direct inquiries to 30 Frost Street, Cambridge, MA 02140
74
 
*/
75
 
 
76
 
#include "mconf.h"
77
 
 
78
 
#ifdef UNK
79
 
static double PI180 = 1.74532925199432957692E-2;
80
 
static double lossth = 1.0e14;
81
 
#endif
82
 
 
83
 
#ifdef DEC
84
 
static unsigned short P1[] = {0036616,0175065,0011224,0164711};
85
 
#define PI180 *(double *)P1
86
 
static double lossth = 8.0e14;
87
 
#endif
88
 
 
89
 
#ifdef IBMPC
90
 
static unsigned short P1[] = {0x9d39,0xa252,0xdf46,0x3f91};
91
 
#define PI180 *(double *)P1
92
 
static double lossth = 1.0e14;
93
 
#endif
94
 
 
95
 
#ifdef MIEEE
96
 
static unsigned short P1[] = {
97
 
0x3f91,0xdf46,0xa252,0x9d39
98
 
};
99
 
#define PI180 *(double *)P1
100
 
static double lossth = 1.0e14;
101
 
#endif
102
 
 
103
 
static double tancot(double, int);
104
 
extern double MAXNUM;
105
 
 
106
 
double
107
 
tandg(double x)
108
 
{
109
 
    return( tancot(x,0) );
110
 
}
111
 
 
112
 
 
113
 
double
114
 
cotdg(double x)
115
 
{
116
 
    return( tancot(x,1) );
117
 
}
118
 
 
119
 
 
120
 
static double
121
 
tancot(double xx, int cotflg)
122
 
{
123
 
    double x;
124
 
    int sign;
125
 
 
126
 
    /* make argument positive but save the sign */
127
 
    if( xx < 0 ) {
128
 
        x = -xx;
129
 
        sign = -1;
130
 
    } else {
131
 
        x = xx;
132
 
        sign = 1;
133
 
    }
134
 
 
135
 
    if( x > lossth ) {
136
 
        mtherr("tandg", TLOSS);
137
 
        return 0.0;
138
 
    }
139
 
 
140
 
    /* modulo 180 */
141
 
    x = x - 180.0*floor(x/180.0);
142
 
    if (cotflg) {
143
 
        if (x <= 90.0) {
144
 
            x = 90.0 - x;
145
 
        } else {
146
 
            x = x - 90.0;
147
 
            sign *= -1;
148
 
        }
149
 
    } else {
150
 
        if (x > 90.0) {
151
 
            x = 180.0 - x;
152
 
            sign *= -1;
153
 
        }
154
 
    }
155
 
    if (x == 0.0) {
156
 
        return 0.0;
157
 
    } else if (x == 45.0) {
158
 
        return sign*1.0;
159
 
    } else if (x == 90.0) {
160
 
        mtherr( (cotflg ? "cotdg" : "tandg"), SING );
161
 
        return MAXNUM;
162
 
    }
163
 
    /* x is now transformed into [0, 90) */
164
 
    return sign * tan(x*PI180);
165
 
}