PatchworkOS
c9fea19
A non-POSIX operating system.
Theme:
Default
Round
Robot
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
#ifndef _SYS_MATH_H
2
#define _SYS_MATH_H 1
3
4
/**
5
* @brief Common math macros.
6
* @ingroup libstd
7
* @defgroup libstd_sys_math Common math macros
8
*
9
* The `sys/math.h` header provides common math macros for operations such as clamping, rounding, and linear
10
* interpolation.
11
*
12
* @{
13
*/
14
15
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
16
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
17
#define CLAMP(x, low, high) MIN((high), MAX((low), (x)))
18
19
#define ROUND_UP(number, multiple) \
20
((((uint64_t)(number) + (uint64_t)(multiple) - 1) / (uint64_t)(multiple)) * (uint64_t)(multiple))
21
#define ROUND_DOWN(number, multiple) (((uint64_t)(number) / (uint64_t)(multiple)) * (uint64_t)(multiple))
22
23
#define LERP_INT(start, end, t, minT, maxT) (((start) * ((maxT) - (t))) + ((end) * ((t) - (minT)))) / ((maxT) - (minT))
24
25
#endif
26
27
/** @} */
include
libstd
sys
math.h
Generated on Mon Dec 15 2025 05:10:34 for PatchworkOS by
1.9.8