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
* Copyright (C) 2022 ML!PA Consulting GmbH
3
*
4
* This file is subject to the terms and conditions of the GNU Lesser
5
* General Public License v2.1. See the file LICENSE in the top level
6
* directory for more details.
7
*/
8
19
#ifndef MACROS_MATH_H
20
#define MACROS_MATH_H
21
22
#ifdef __cplusplus
23
extern
"C"
{
24
#endif
25
29
#define SIGNOF(a) _Generic(a, unsigned char: 1, \
30
unsigned short: 1, \
31
unsigned int: 1, \
32
unsigned long: 1, \
33
unsigned long long: 1, \
34
default: ((a) <= 0 ? ((a) == 0 ? 1L : -1L ): 1L))
38
#define DIV_ROUND(a, b) ((SIGNOF(a) * ((SIGNOF(a) * (a)) + (SIGNOF(b) * (b)) / 2) / (b)))
39
43
#define DIV_ROUND_UP(a, b) ((SIGNOF(a)>0 && SIGNOF(b)>0) ? (((a) + (b) - 1) / (b)):\
44
(SIGNOF(a)<0 && SIGNOF(b)<0) ? (((a) + (b) + 1) / (b)): (a) / (b))
45
49
#define DIV_ROUND_INF(a, b) (SIGNOF(a) * (((SIGNOF(a) * (a)) + (SIGNOF(b) * (b)) - 1) / (b)))
50
54
#define MATH_ALIGN(num, chunk) ((chunk) * DIV_ROUND_INF(num, chunk))
55
56
#ifdef __cplusplus
57
}
58
#endif
59
60
#endif
/* MACROS_MATH_H */
Generated on Sat Nov 23 2024 16:31:07 by
1.9.8