Speeduino
Loading...
Searching...
No Matches
Macros
Rounding behavior
Collaboration diagram for Rounding behavior:

Macros

#define DIV_ROUND_DOWN   -1
 Rounding behavior: always round down.
 
#define DIV_ROUND_UP   1
 Rounding behavior: always round up.
 
#define DIV_ROUND_NEAREST   0
 Rounding behavior: round to nearest.
 
#define DIV_ROUND_BEHAVIOR   DIV_ROUND_NEAREST
 Integer division rounding behavior.
 
#define DIV_ROUND_CORRECT(d, t)   ((t)(((d)>>1U)+(t)DIV_ROUND_BEHAVIOR))
 Computes the denominator correction for rounding division based on our rounding behavior.
 

Detailed Description

Macro Definition Documentation

◆ DIV_ROUND_BEHAVIOR

#define DIV_ROUND_BEHAVIOR   DIV_ROUND_NEAREST

Integer division rounding behavior.

◆ DIV_ROUND_CORRECT

#define DIV_ROUND_CORRECT (   d,
  t 
)    ((t)(((d)>>1U)+(t)DIV_ROUND_BEHAVIOR))

Computes the denominator correction for rounding division based on our rounding behavior.

Parameters
dThe divisor (an integer)
tThe type of the result. E.g. uint16_t

◆ DIV_ROUND_DOWN

#define DIV_ROUND_DOWN   -1

Rounding behavior: always round down.

◆ DIV_ROUND_NEAREST

#define DIV_ROUND_NEAREST   0

Rounding behavior: round to nearest.

This rounds 0.5 away from zero. This is the same behavior as the standard library round() function.

◆ DIV_ROUND_UP

#define DIV_ROUND_UP   1

Rounding behavior: always round up.