30#define _USE_MATH_DEFINES
40#define to_radians(x) ( (x) * (M_PI / 180.0 ))
41#define to_degrees(x) ( (x) * (180.0 / M_PI ))
51static inline int dequals_mag(
double a,
double b,
double thresh)
53 return (fabs(a-b) < thresh);
56static inline int isq(
int v)
61static inline float fsq(
float v)
66static inline double sq(
double v)
71static inline double sgn(
double v)
73 return (v>=0) ? 1 : -1;
79 return (
float)(rand() / (RAND_MAX + 1.0));
89static inline int irand(
int bound)
91 int v = (int) (
randf()*bound);
102 return vin - M_2_PI * floor(vin / M_2_PI);
114 return ref +
mod2pi(vin - ref);
120 return vin - 360 * floor(vin / 360);
130 return (vin % mod + mod) % mod;
136 int v = (int) (theta / M_2_PI * max);
141 assert (v >= 0 && v < max);
146static inline int imin(
int a,
int b)
148 return (a < b) ? a : b;
151static inline int imax(
int a,
int b)
153 return (a > b) ? a : b;
156static inline int64_t
imin64(int64_t a, int64_t b)
158 return (a < b) ? a : b;
161static inline int64_t
imax64(int64_t a, int64_t b)
163 return (a > b) ? a : b;
166static inline int iclamp(
int v,
int minv,
int maxv)
171static inline double dclamp(
double a,
double min,
double max)
180static inline int fltcmp (
float f1,
float f2)
182 float epsilon = f1-f2;
185 else if (epsilon > 0.0)
191static inline int dblcmp (
double d1,
double d2)
193 double epsilon = d1-d2;
196 else if (epsilon > 0.0)
static double mod2pi_positive(double vin)
Map vin to [0, 2*PI)
Definition math_util.h:100
static int fltcmp(float f1, float f2)
Definition math_util.h:180
static float fsq(float v)
Definition math_util.h:61
static float signed_randf(void)
Definition math_util.h:83
static double mod360_positive(double vin)
Map vin to [0, 360)
Definition math_util.h:118
static double dclamp(double a, double min, double max)
Definition math_util.h:171
static double mod2pi_ref(double ref, double vin)
Return vin such that it is within PI degrees of ref.
Definition math_util.h:112
static double mod360(double vin)
Map vin to [-180, 180)
Definition math_util.h:124
static int theta_to_int(double theta, int max)
Definition math_util.h:133
static int isq(int v)
Definition math_util.h:56
static float randf(void)
Definition math_util.h:77
static int mod_positive(int vin, int mod)
Definition math_util.h:129
static int64_t imin64(int64_t a, int64_t b)
Definition math_util.h:156
static double sgn(double v)
Definition math_util.h:71
static int dequals_mag(double a, double b, double thresh)
Definition math_util.h:51
static int imin(int a, int b)
Definition math_util.h:146
static int irand(int bound)
Definition math_util.h:89
static int64_t imax64(int64_t a, int64_t b)
Definition math_util.h:161
static double sq(double v)
Definition math_util.h:66
static double mod2pi(double vin)
Map vin to [-PI, PI)
Definition math_util.h:106
static int dblcmp(double d1, double d2)
Definition math_util.h:191
static int iclamp(int v, int minv, int maxv)
Definition math_util.h:166
static int imax(int a, int b)
Definition math_util.h:151