]> git.lizzy.rs Git - nothing.git/blob - src/math/extrema.h
1f49bd28ce4cfa2686fb140ee88abef05dadef0b
[nothing.git] / src / math / extrema.h
1 #ifndef EXTREMA_H_
2 #define EXTREMA_H_
3
4 #include <stdint.h>
5
6 #define MAX_INSTANCE(type)                      \
7     static inline                               \
8     type max_##type(type a, type b) {           \
9         return a > b ? a : b;                   \
10     }                                           \
11
12 MAX_INSTANCE(float)
13 MAX_INSTANCE(int64_t)
14 MAX_INSTANCE(size_t)
15 #define MAX(type, a, b) max_##type(a, b)
16
17 #define MIN_INSTANCE(type)                      \
18     static inline                               \
19     type min_##type(type a, type b) {           \
20         return a < b ? a : b;                   \
21     }                                           \
22
23 MIN_INSTANCE(float)
24 MIN_INSTANCE(int64_t)
25 MIN_INSTANCE(size_t)
26 #define MIN(type, a, b) min_##type(a, b)
27
28 #endif  // EXTREMA_H_