55 #define PI 3.141592653589793f
61 #define MATH_DEG_TO_RAD (PI/180.0f)
67 #define MATH_RAD_TO_DEG (180.0f/PI)
86 float static inline maths_deg_to_rad(
float i)
88 return MATH_DEG_TO_RAD * i;
98 float static inline maths_rad_to_deg(
float i)
100 return MATH_RAD_TO_DEG * i;
111 float static inline maths_calc_smaller_angle(
float angle)
114 while (out<-PI) out += 2.0f * PI;
115 while (out>=PI) out -= 2.0f * PI;
127 float static inline maths_fast_sqrt(
float number)
136 const float f = 1.5f;
140 i.l = 0x5f3759df - ( i.l >> 1 );
142 y = y * ( f - ( x * y * y ) );
143 y = y * ( f - ( x * y * y ) );
155 float static inline maths_fast_sqrt_1(
float input)
164 result = 0.5f * (result + (input / result));
165 result = 0.5f * (result + (input / result));
178 static inline float maths_f_abs(
const float a)
199 static inline float maths_f_min(
const float a,
const float b)
220 static inline float maths_f_max(
const float a,
const float b){
242 static float inline maths_clip(
float input_value,
float clip_value)
244 if (input_value>clip_value)
return clip_value;
245 if (input_value<-clip_value)
return -clip_value;
258 static float inline maths_soft_zone(
float x,
float soft_zone_width)
260 if (soft_zone_width < 0.0000001f)
266 return x * x * x / ( SQR(soft_zone_width) + SQR(x) );
277 static float inline maths_sigmoid(
float x)
279 return (x / maths_fast_sqrt(1 + SQR(x)));
289 static float inline maths_center_window_2(
float x)
291 return 1.0f / (1 + SQR(x));
301 static float inline maths_center_window_4(
float x)
303 return 1.0f / (1 + SQR(SQR(x)));
318 static float inline maths_median_filter_3x(
float a,
float b,
float c)
322 if ((a <= b) && (a <= c))
324 middle = (b <= c) ? b : c;
326 else if ((b <= a) && (b <= c))
328 middle = (a <= c) ? a : c;
332 middle = (a <= b) ? a : b;
352 static inline float maths_interpolate(
float x,
float x1,
float x2,
float y1,
float y2)
360 float y = y1 + (y2 - y1) * (x - x1) / (x2 - x1);