PatchworkOS
19e446b
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
#include <
stdint.h
>
5
6
/**
7
* @brief Helper Macros for math operations.
8
* @ingroup libstd
9
* @defgroup libstd_sys_math Math Helpers
10
*
11
* The `sys/math.h` header provides common math macros for operations such as clamping, rounding, and linear
12
* interpolation.
13
*
14
* @{
15
*/
16
17
#define MAX(x, y) (((x) > (y)) ? (x) : (y))
18
#define MIN(x, y) (((x) < (y)) ? (x) : (y))
19
#define CLAMP(x, low, high) MIN((high), MAX((low), (x)))
20
21
#define ROUND_UP(number, multiple) \
22
((((uint64_t)(number) + (uint64_t)(multiple) - 1) / (uint64_t)(multiple)) * (uint64_t)(multiple))
23
#define ROUND_DOWN(number, multiple) (((uint64_t)(number) / (uint64_t)(multiple)) * (uint64_t)(multiple))
24
25
#define LERP_INT(start, end, t, minT, maxT) (((start) * ((maxT) - (t))) + ((end) * ((t) - (minT)))) / ((maxT) - (minT))
26
27
#define IS_POW2(x) (((x) & ((x) - 1)) == 0)
28
29
uint64_t
next_pow2
(
uint64_t
n);
30
31
#endif
32
33
/** @} */
next_pow2
uint64_t next_pow2(uint64_t n)
Definition
new_pow2.c:3
stdint.h
uint64_t
__UINT64_TYPE__ uint64_t
Definition
stdint.h:17
include
sys
math.h
Generated on Sat Jan 24 2026 10:59:24 for PatchworkOS by
1.9.8