Math helper macros.
More...
Go to the source code of this file.
#define | SIGNOF(a) |
| Returns the sign of a , either -1 or 1.
|
|
#define | DIV_ROUND(a, b) |
| Calculates a/ b with arithmetic rounding (.5 away from zero)
|
|
#define | DIV_ROUND_UP(a, b) |
| Calculates a/ b , always rounding up (towards positive infinity)
|
|
#define | DIV_ROUND_INF(a, b) |
| Calculates a/ b , always rounding away from zero (towards positive and negative inf)
|
|
#define | MATH_ALIGN(num, chunk) |
| Align num with the next multiple of chunk .
|
|
◆ DIV_ROUND
#define DIV_ROUND |
( |
| a, |
|
|
| b ) |
Value:
#define SIGNOF(a)
Returns the sign of a, either -1 or 1.
Calculates a/
b
with arithmetic rounding (.5 away from zero)
Definition at line 38 of file math.h.
◆ DIV_ROUND_INF
#define DIV_ROUND_INF |
( |
| a, |
|
|
| b ) |
Value:
Calculates a/
b
, always rounding away from zero (towards positive and negative inf)
Definition at line 49 of file math.h.
◆ DIV_ROUND_UP
#define DIV_ROUND_UP |
( |
| a, |
|
|
| b ) |
Value:
(
SIGNOF(a)<0 &&
SIGNOF(b)<0) ? (((a) + (b) + 1) / (b)): (a) / (b))
Calculates a/
b
, always rounding up (towards positive infinity)
Definition at line 43 of file math.h.
◆ MATH_ALIGN
#define MATH_ALIGN |
( |
| num, |
|
|
| chunk ) |
Value:
#define DIV_ROUND_INF(a, b)
Calculates a/ b, always rounding away from zero (towards positive and negative inf)
Align num
with the next multiple of chunk
.
Definition at line 54 of file math.h.
◆ SIGNOF
Value: _Generic(a, unsigned char: 1, \
unsigned short: 1, \
unsigned int: 1, \
unsigned long: 1, \
unsigned long long: 1, \
default: ((a) <= 0 ? ((a) == 0 ? 1L : -1L ): 1L))
Returns the sign of a
, either -1 or 1.
Definition at line 29 of file math.h.