sinpi.c
Go to the documentation of this file.
1 /*
2  * Implement sin(pi * x) and cos(pi * x) for real x. Since the periods
3  * of these functions are integral (and thus representable in double
4  * precision), it's possible to compute them with greater accuracy
5  * than sin(x) and cos(x).
6  */
7 #include "mconf.h"
8 
9 
10 /* Compute sin(pi * x). */
11 double sinpi(double x)
12 {
13  double s = 1.0;
14  double r;
15 
16  if (x < 0.0) {
17  x = -x;
18  s = -1.0;
19  }
20 
21  r = fmod(x, 2.0);
22  if (r < 0.5) {
23  return s*sin(M_PI*r);
24  }
25  else if (r > 1.5) {
26  return s*sin(M_PI*(r - 2.0));
27  }
28  else {
29  return -s*sin(M_PI*(r - 1.0));
30  }
31 }
32 
33 
34 /* Compute cos(pi * x) */
35 double cospi(double x)
36 {
37  double r;
38 
39  if (x < 0.0) {
40  x = -x;
41  }
42 
43  r = fmod(x, 2.0);
44  if (r == 0.5) {
45  // We don't want to return -0.0
46  return 0.0;
47  }
48  if (r < 1.0) {
49  return -sin(M_PI*(r - 0.5));
50  }
51  else {
52  return sin(M_PI*(r - 1.5));
53  }
54 }
s
RealScalar s
Definition: level1_cplx_impl.h:126
ceres::sin
Jet< T, N > sin(const Jet< T, N > &f)
Definition: jet.h:439
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
Eigen::bfloat16_impl::fmod
EIGEN_STRONG_INLINE EIGEN_DEVICE_FUNC bfloat16 fmod(const bfloat16 &a, const bfloat16 &b)
Definition: BFloat16.h:567
mconf.h
M_PI
#define M_PI
Definition: mconf.h:117
cospi
double cospi(double x)
Definition: sinpi.c:35
sinpi
double sinpi(double x)
Definition: sinpi.c:11


gtsam
Author(s):
autogenerated on Fri Nov 1 2024 03:35:26