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
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:58
static TIntegral readSerialIntegralTimeout(void)
Reads an integral type, timing out if necessary.
Definition comms.cpp:175
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 |
◆ div_round_closest_u16()
Rounded unsigned integer division optimized for compile time constants.
- Template Parameters
-
- Parameters
-
- Returns
- uint16_t