Toggle navigation
Documentation
The friendly Operating System for the Internet of Things
Loading...
Searching...
No Matches
math.h
Go to the documentation of this file.
1
/*
2
* SPDX-FileCopyrightText: 2022 ML!PA Consulting GmbH
3
* SPDX-License-Identifier: LGPL-2.1-only
4
*/
5
6
#pragma once
7
17
18
#ifdef __cplusplus
19
extern
"C"
{
20
#endif
21
25
#define SIGNOF(a) _Generic(a, unsigned char: 1, \
26
unsigned short: 1, \
27
unsigned int: 1, \
28
unsigned long: 1, \
29
unsigned long long: 1, \
30
default: ((a) <= 0 ? ((a) == 0 ? 1L : -1L ): 1L))
31
34
#define DIV_ROUND(a, b) ((SIGNOF(a) * ((SIGNOF(a) * (a)) + (SIGNOF(b) * (b)) / 2) / (b)))
35
39
#define DIV_ROUND_UP(a, b) ((SIGNOF(a)>0 && SIGNOF(b)>0) ? (((a) + (b) - 1) / (b)):\
40
(SIGNOF(a)<0 && SIGNOF(b)<0) ? (((a) + (b) + 1) / (b)): (a) / (b))
41
45
#define DIV_ROUND_INF(a, b) (SIGNOF(a) * (((SIGNOF(a) * (a)) + (SIGNOF(b) * (b)) - 1) / (b)))
46
50
#define MATH_ALIGN(num, chunk) ((chunk) * DIV_ROUND_INF(num, chunk))
51
52
#ifdef __cplusplus
53
}
54
#endif
55
Generated on Sun Nov 23 2025 23:27:56 by
1.13.2