Integer division returns the quotient. I.e. rounds to zero. This code will round the result to nearest integer. Rounding behavior is controlled by DIV_ROUND_BEHAVIOR.
More...
Integer division returns the quotient. I.e. rounds to zero. This code will round the result to nearest integer. Rounding behavior is controlled by DIV_ROUND_BEHAVIOR.
◆ DIV_ROUND_CLOSEST
| #define DIV_ROUND_CLOSEST |
( |
|
n, |
|
|
|
d, |
|
|
|
t |
|
) |
| |
Value: ( \
(((n) < (t)(0)) ^ ((d) < (t)(0))) ? \
#define DIV_ROUND_CORRECT(d, t)
Computes the denominator correction for rounding division based on our rounding behavior.
Definition maths.h:73
Rounded integer division.
Integer division returns the quotient. I.e. rounds to zero. This macro will round the result to nearest integer. Rounding behavior is controlled by DIV_ROUND_BEHAVIOR
- Warning
- For performance reasons, this macro does not promote integers. So it will overflow if n>MAX(t)-(d/2).
- Parameters
-
| n | The numerator (dividee) (an integer) |
| d | The denominator (divider) (an integer) |
| t | The type of the result. E.g. uint16_t |
◆ UDIV_ROUND_CLOSEST
Rounded unsigned integer division.
This is slightly faster than the signed version (DIV_ROUND_CLOSEST(n, d, t))
- Warning
- For performance reasons, this macro does not promote integers. So it will overflow if n>MAX(t)-(d/2).
- Parameters
-
| n | The numerator (dividee) (an unsigned integer) |
| d | The denominator (divider) (an unsigned integer) |
| t | The type of the result. E.g. uint16_t |
◆ UDIV_ROUND_UP
| #define UDIV_ROUND_UP |
( |
|
n, |
|
|
|
d, |
|
|
|
t |
|
) |
| ((t)((n) + (t)((d)+1U))/(t)(d)) |
Rounding up unsigned integer division.
◆ div_round_closest_u16()
template<uint16_t divisor>
Rounded unsigned integer division optimized for compile time constants.
- Template Parameters
-
- Parameters
-
- Returns
- uint16_t