tandg.c
Go to the documentation of this file.
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  * IEEE 0,10 30000 3.2e-16 8.4e-17
30  *
31  * ERROR MESSAGES:
32  *
33  * message condition value returned
34  * tandg total loss x > 1.0e14 (IEEE) 0.0
35  * tandg singularity x = 180 k + 90 INFINITY
36  */
37  /* cotdg.c
38  *
39  * Circular cotangent of argument in degrees
40  *
41  *
42  *
43  * SYNOPSIS:
44  *
45  * double x, y, cotdg();
46  *
47  * y = cotdg( x );
48  *
49  *
50  *
51  * DESCRIPTION:
52  *
53  * Returns the circular cotangent of the argument x in degrees.
54  *
55  * Range reduction is modulo pi/4. A rational function
56  * x + x**3 P(x**2)/Q(x**2)
57  * is employed in the basic interval [0, pi/4].
58  *
59  *
60  * ERROR MESSAGES:
61  *
62  * message condition value returned
63  * cotdg total loss x > 1.0e14 (IEEE) 0.0
64  * cotdg singularity x = 180 k INFINITY
65  */
66 
67 /*
68  * Cephes Math Library Release 2.0: April, 1987
69  * Copyright 1984, 1987 by Stephen L. Moshier
70  * Direct inquiries to 30 Frost Street, Cambridge, MA 02140
71  */
72 
73 #include "mconf.h"
74 
75 static double PI180 = 1.74532925199432957692E-2;
76 static double lossth = 1.0e14;
77 
78 static double tancot(double, int);
79 
80 double tandg(double x)
81 {
82  return (tancot(x, 0));
83 }
84 
85 
86 double cotdg(double x)
87 {
88  return (tancot(x, 1));
89 }
90 
91 
92 static double tancot(double xx, int cotflg)
93 {
94  double x;
95  int sign;
96 
97  /* make argument positive but save the sign */
98  if (xx < 0) {
99  x = -xx;
100  sign = -1;
101  }
102  else {
103  x = xx;
104  sign = 1;
105  }
106 
107  if (x > lossth) {
108  sf_error("tandg", SF_ERROR_NO_RESULT, NULL);
109  return 0.0;
110  }
111 
112  /* modulo 180 */
113  x = x - 180.0 * floor(x / 180.0);
114  if (cotflg) {
115  if (x <= 90.0) {
116  x = 90.0 - x;
117  }
118  else {
119  x = x - 90.0;
120  sign *= -1;
121  }
122  }
123  else {
124  if (x > 90.0) {
125  x = 180.0 - x;
126  sign *= -1;
127  }
128  }
129  if (x == 0.0) {
130  return 0.0;
131  }
132  else if (x == 45.0) {
133  return sign * 1.0;
134  }
135  else if (x == 90.0) {
136  sf_error((cotflg ? "cotdg" : "tandg"), SF_ERROR_SINGULAR, NULL);
137  return INFINITY;
138  }
139  /* x is now transformed into [0, 90) */
140  return sign * tan(x * PI180);
141 }
SF_ERROR_NO_RESULT
@ SF_ERROR_NO_RESULT
Definition: sf_error.h:15
x
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
Definition: gnuplot_common_settings.hh:12
PI180
static double PI180
Definition: tandg.c:75
sign
const EIGEN_DEVICE_FUNC SignReturnType sign() const
Definition: ArrayCwiseUnaryOps.h:219
tancot
static double tancot(double, int)
Definition: tandg.c:92
cotdg
double cotdg(double x)
Definition: tandg.c:86
tan
const EIGEN_DEVICE_FUNC TanReturnType tan() const
Definition: ArrayCwiseUnaryOps.h:269
lossth
static double lossth
Definition: tandg.c:76
mconf.h
sf_error
void sf_error(const char *func_name, sf_error_t code, const char *fmt,...)
Definition: sf_error.c:41
SF_ERROR_SINGULAR
@ SF_ERROR_SINGULAR
Definition: sf_error.h:10
tandg
double tandg(double x)
Definition: tandg.c:80
NULL
#define NULL
Definition: ccolamd.c:609
floor
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
Definition: ArrayCwiseUnaryOps.h:481


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:36:55