12constexpr float pi = 3.1415926535897932384626433f;
16 return f > 0 ? (int)(f + 0.5f) : (int)(f - 0.5f);
24template<
typename T,
typename TB>
25constexpr inline T
mix(
const T a,
const T b, TB amount)
27 return a + (b - a) * amount;
30template<
typename T,
typename TB>
31inline T
bezier(
const T p0,
const T p1,
const T p2,
const T p3, TB amount)
34 const T c10 =
mix(p0, p1, amount);
35 const T c11 =
mix(p1, p2, amount);
36 const T c12 =
mix(p2, p3, amount);
38 const T c20 =
mix(c10, c11, amount);
39 const T c21 =
mix(c11, c12, amount);
41 return mix(c20, c21, amount);
44template<
typename T,
typename TB>
45inline T
mix_polynomial(
const TB time[],
const T data[],
int samples, TB amount, T init)
48 for(
int i = 0; i < samples; i++)
51 for(
int j = 0; j < samples; j++)
53 term = term * (amount - time[j]) / TB(time[i] - time[j]);
61 return rand() / (float)(RAND_MAX);
76 return 2.0f *
pi * (rand() / std::nextafter((
float)RAND_MAX, std::numeric_limits<float>::max()));
82constexpr inline int f2fx(
float v)
86constexpr inline float fx2f(
int v)
92constexpr inline int i2fx(
int v)
96constexpr inline int fx2i(
int v)
128 operator float()
const
137 return std::min(a, b);
142 return std::min(std::min(a, b), c);
147 return std::max(a, b);
152 return std::max(std::max(a, b), c);
157 return a < T(0) ? -a : a;
163 return lower <= a && a <= upper;
void set(int v)
Definition: math.h:106
int value
Definition: math.h:103
int get() const
Definition: math.h:110
fxp & operator=(float v)
Definition: math.h:119
fxp & operator=(int v)
Definition: math.h:114
constexpr float pi
Definition: math.h:12
constexpr T minimum(T a, T b)
Definition: math.h:135
float random_float()
Definition: math.h:59
constexpr int fx2i(int v)
Definition: math.h:96
constexpr int fxpscale
Definition: math.h:79
constexpr float fx2f(int v)
Definition: math.h:86
constexpr T in_range(T a, T lower, T upper)
Definition: math.h:161
float random_angle()
Definition: math.h:74
constexpr T mix(const T a, const T b, TB amount)
Definition: math.h:25
constexpr int i2fx(int v)
Definition: math.h:92
constexpr int round_to_int(float f)
Definition: math.h:14
T mix_polynomial(const TB time[], const T data[], int samples, TB amount, T init)
Definition: math.h:45
constexpr T maximum(T a, T b)
Definition: math.h:145
constexpr int f2fx(float v)
Definition: math.h:82
constexpr int round_truncate(float f)
Definition: math.h:19
constexpr T absolute(T a)
Definition: math.h:155
T bezier(const T p0, const T p1, const T p2, const T p3, TB amount)
Definition: math.h:31