sindg.c
Go to the documentation of this file.
1 /* sindg.c
2  *
3  * Circular sine of angle in degrees
4  *
5  *
6  *
7  * SYNOPSIS:
8  *
9  * double x, y, sindg();
10  *
11  * y = sindg( x );
12  *
13  *
14  *
15  * DESCRIPTION:
16  *
17  * Range reduction is into intervals of 45 degrees.
18  *
19  * Two polynomial approximating functions are employed.
20  * Between 0 and pi/4 the sine is approximated by
21  * x + x**3 P(x**2).
22  * Between pi/4 and pi/2 the cosine is represented as
23  * 1 - x**2 P(x**2).
24  *
25  *
26  *
27  * ACCURACY:
28  *
29  * Relative error:
30  * arithmetic domain # trials peak rms
31  * IEEE +-1000 30000 2.3e-16 5.6e-17
32  *
33  * ERROR MESSAGES:
34  *
35  * message condition value returned
36  * sindg total loss x > 1.0e14 (IEEE) 0.0
37  *
38  */
39  /* cosdg.c
40  *
41  * Circular cosine of angle in degrees
42  *
43  *
44  *
45  * SYNOPSIS:
46  *
47  * double x, y, cosdg();
48  *
49  * y = cosdg( x );
50  *
51  *
52  *
53  * DESCRIPTION:
54  *
55  * Range reduction is into intervals of 45 degrees.
56  *
57  * Two polynomial approximating functions are employed.
58  * Between 0 and pi/4 the cosine is approximated by
59  * 1 - x**2 P(x**2).
60  * Between pi/4 and pi/2 the sine is represented as
61  * x + x**3 P(x**2).
62  *
63  *
64  * ACCURACY:
65  *
66  * Relative error:
67  * arithmetic domain # trials peak rms
68  * IEEE +-1000 30000 2.1e-16 5.7e-17
69  * See also sin().
70  *
71  */
72 
73 /* Cephes Math Library Release 2.0: April, 1987
74  * Copyright 1985, 1987 by Stephen L. Moshier
75  * Direct inquiries to 30 Frost Street, Cambridge, MA 02140 */
76 
77 #include "mconf.h"
78 
79 static double sincof[] = {
80  1.58962301572218447952E-10,
81  -2.50507477628503540135E-8,
82  2.75573136213856773549E-6,
83  -1.98412698295895384658E-4,
84  8.33333333332211858862E-3,
85  -1.66666666666666307295E-1
86 };
87 
88 static double coscof[] = {
89  1.13678171382044553091E-11,
90  -2.08758833757683644217E-9,
91  2.75573155429816611547E-7,
92  -2.48015872936186303776E-5,
93  1.38888888888806666760E-3,
94  -4.16666666666666348141E-2,
95  4.99999999999999999798E-1
96 };
97 
98 static double PI180 = 1.74532925199432957692E-2; /* pi/180 */
99 static double lossth = 1.0e14;
100 
101 double sindg(double x)
102 {
103  double y, z, zz;
104  int j, sign;
105 
106  /* make argument positive but save the sign */
107  sign = 1;
108  if (x < 0) {
109  x = -x;
110  sign = -1;
111  }
112 
113  if (x > lossth) {
114  sf_error("sindg", SF_ERROR_NO_RESULT, NULL);
115  return (0.0);
116  }
117 
118  y = floor(x / 45.0); /* integer part of x/M_PI_4 */
119 
120  /* strip high bits of integer part to prevent integer overflow */
121  z = ldexp(y, -4);
122  z = floor(z); /* integer part of y/8 */
123  z = y - ldexp(z, 4); /* y - 16 * (y/16) */
124 
125  j = z; /* convert to integer for tests on the phase angle */
126  /* map zeros to origin */
127  if (j & 1) {
128  j += 1;
129  y += 1.0;
130  }
131  j = j & 07; /* octant modulo 360 degrees */
132  /* reflect in x axis */
133  if (j > 3) {
134  sign = -sign;
135  j -= 4;
136  }
137 
138  z = x - y * 45.0; /* x mod 45 degrees */
139  z *= PI180; /* multiply by pi/180 to convert to radians */
140  zz = z * z;
141 
142  if ((j == 1) || (j == 2)) {
143  y = 1.0 - zz * polevl(zz, coscof, 6);
144  }
145  else {
146  y = z + z * (zz * polevl(zz, sincof, 5));
147  }
148 
149  if (sign < 0)
150  y = -y;
151 
152  return (y);
153 }
154 
155 
156 double cosdg(double x)
157 {
158  double y, z, zz;
159  int j, sign;
160 
161  /* make argument positive */
162  sign = 1;
163  if (x < 0)
164  x = -x;
165 
166  if (x > lossth) {
167  sf_error("cosdg", SF_ERROR_NO_RESULT, NULL);
168  return (0.0);
169  }
170 
171  y = floor(x / 45.0);
172  z = ldexp(y, -4);
173  z = floor(z); /* integer part of y/8 */
174  z = y - ldexp(z, 4); /* y - 16 * (y/16) */
175 
176  /* integer and fractional part modulo one octant */
177  j = z;
178  if (j & 1) { /* map zeros to origin */
179  j += 1;
180  y += 1.0;
181  }
182  j = j & 07;
183  if (j > 3) {
184  j -= 4;
185  sign = -sign;
186  }
187 
188  if (j > 1)
189  sign = -sign;
190 
191  z = x - y * 45.0; /* x mod 45 degrees */
192  z *= PI180; /* multiply by pi/180 to convert to radians */
193 
194  zz = z * z;
195 
196  if ((j == 1) || (j == 2)) {
197  y = z + z * (zz * polevl(zz, sincof, 5));
198  }
199  else {
200  y = 1.0 - zz * polevl(zz, coscof, 6);
201  }
202 
203  if (sign < 0)
204  y = -y;
205 
206  return (y);
207 }
208 
209 
210 /* Degrees, minutes, seconds to radians: */
211 
212 /* 1 arc second, in radians = 4.848136811095359935899141023579479759563533023727e-6 */
213 static double P64800 =
214  4.848136811095359935899141023579479759563533023727e-6;
215 
216 double radian(double d, double m, double s)
217 {
218  return (((d * 60.0 + m) * 60.0 + s) * P64800);
219 }
coscof
static double coscof[]
Definition: sindg.c:88
s
RealScalar s
Definition: level1_cplx_impl.h:126
d
static const double d[K][N]
Definition: igam.h:11
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
sign
const EIGEN_DEVICE_FUNC SignReturnType sign() const
Definition: ArrayCwiseUnaryOps.h:219
cosdg
double cosdg(double x)
Definition: sindg.c:156
radian
double radian(double d, double m, double s)
Definition: sindg.c:216
lossth
static double lossth
Definition: sindg.c:99
j
std::ptrdiff_t j
Definition: tut_arithmetic_redux_minmax.cpp:2
PI180
static double PI180
Definition: sindg.c:98
polevl
static double polevl(double x, const double coef[], int N)
Definition: polevl.h:65
P64800
static double P64800
Definition: sindg.c:213
pybind_wrapper_test_script.z
z
Definition: pybind_wrapper_test_script.py:61
m
Matrix3f m
Definition: AngleAxis_mimic_euler.cpp:1
sindg
double sindg(double x)
Definition: sindg.c:101
y
Scalar * y
Definition: level1_cplx_impl.h:124
mconf.h
sf_error
void sf_error(const char *func_name, sf_error_t code, const char *fmt,...)
Definition: sf_error.c:41
NULL
#define NULL
Definition: ccolamd.c:609
sincof
static double sincof[]
Definition: sindg.c:79
floor
const EIGEN_DEVICE_FUNC FloorReturnType floor() const
Definition: ArrayCwiseUnaryOps.h:481


gtsam
Author(s):
autogenerated on Sat Nov 16 2024 04:04:19