Add macro for round up/down integer division

This commit is contained in:
Josh Stewart 2017-01-30 17:11:13 +11:00
parent 23c3c8b6bf
commit 13142c1477
1 changed files with 2 additions and 0 deletions

View File

@ -1,5 +1,7 @@
#include "maths.h" #include "maths.h"
#define DIV_ROUND_CLOSEST(n, d) ((((n) < 0) ^ ((d) < 0)) ? (((n) - (d)/2)/(d)) : (((n) + (d)/2)/(d)))
//Replace the standard arduino map() function to use the div function instead //Replace the standard arduino map() function to use the div function instead
int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max) int fastMap(unsigned long x, int in_min, int in_max, int out_min, int out_max)
{ {