3 #ifndef __stir_modulo_H__ 4 #define __stir_modulo_H__ 52 modulo(
const double a,
const double b)
54 const double res = fmod(a, b);
55 return res < 0 ? res + fabs(b) : res;
72 float res =
static_cast<float>(
modulo(static_cast<double>(a), static_cast<double>(b)));
74 const float abs_b = b >= 0 ? b : -b;
89 const int res = a % b;
90 const int res2 = res < 0 ? res + (b >= 0 ? b : -b) : res;
92 assert(res2 < (b >= 0 ? b : -b));
101 template <
int num_dimensions,
typename T>
106 for (
int d = 1; d <= num_dimensions; ++d)
107 result[d] =
modulo(a[d], b[d]);
116 template <
typename FloatOrDouble>
120 static const FloatOrDouble two_pi =
static_cast<FloatOrDouble
>(2 *
_PI);
121 assert(phi >= -two_pi);
122 assert(phi < two_pi);
125 FloatOrDouble res = phi + two_pi;
130 assert(res < two_pi);
136 template <
typename FloatOrDouble>
140 return modulo(phi, static_cast<FloatOrDouble>(2 *
_PI));
#define _PI
The constant pi to high precision.
Definition: common.h:134
FloatOrDouble from_min_pi_plus_pi_to_0_2pi(const FloatOrDouble phi)
A function to convert an angle from one range to another.
Definition: modulo.h:118
FloatOrDouble to_0_2pi(const FloatOrDouble phi)
Convert angle to standard range.
Definition: modulo.h:138
BasicCoordinate< num_dimensions, T > modulo(const BasicCoordinate< num_dimensions, T > &a, const BasicCoordinate< num_dimensions, T > &b)
Performs the modulus operation on each element of the coordinates.
Definition: modulo.h:103
class BasicCoordinate<int num_dimensions, typename coordT> defines num_dimensions -dimensional coordi...
Definition: BasicCoordinate.h:53
basic configuration include file