summaryrefslogtreecommitdiff
path: root/include/c/c_math.h
blob: 914eff24479af4a4ae9e301a28d2bfcb628da0fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#ifndef C_LIB_CMATH
#define C_LIB_CMATH

#include "common.h"
#include "egg/math/eggMath.h"

#include <cmath.h>

namespace cM {
s16 atan2s(f32, f32);
f32 atan2f(f32, f32);

void initRnd(s32);
f32 rnd();
int rndInt(int max);
f32 rndF(f32 max);
f32 rndFX(f32 amp);

template <typename T>
T rndRange(T min, T max) {
    f32 r = cM::rndF(max - min);
    f32 m = min;
    m += r;
    return m;
}

template <typename T>
inline T minMaxLimit(T val, T min, T max) {
    return (T)((T)val < (T)min ? (T)min : ((T)val > (T)max ? (T)max : (T)val));
}

inline bool isZero(f32 val) {
    return std::fabsf(val) <= EGG::Math<f32>::epsilon();
}

// When possivle, use the `isZero` func above.
// There are small cases where the result of fabs needs to be used again
inline bool isLessThanZero(f32 val) {
    return val <= EGG::Math<f32>::epsilon();
}

} // namespace cM

#endif