summaryrefslogtreecommitdiff
path: root/include/tinyff/math/core.h
blob: 946cbe7c0a3852505469c0385cc7a3b4c30f603e (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
45
46
47
48
#ifndef FF_MATH_H
#define FF_MATH_H

// Static inline functions for type safety over macros



static inline int ff_maxi(int a, int b)
{
    return a > b ? a : b;
}

static inline float ff_maxf(float a, float b)
{
    return a > b ? a : b;
}

static inline int ff_mini(int a, int b)
{
    return a < b ? a : b;
}

static inline float ff_minf(float a, float b)
{
    return a < b ? a : b;
}

static inline int ff_clampi(int x, int low, int high)
{
    return ff_maxi(low, ff_mini(x, high));
}

static inline float ff_clampf(float x, float low, float high)
{
    return ff_maxf(low, ff_minf(x, high));
}

static inline int ff_absi(int x)
{
    return x < 0 ? -x : x;
}

static inline float ff_absf(float x)
{
    return x < 0 ? -x : x;
}

#endif