Commit 89feacb8 authored by Artur Bieniek's avatar Artur Bieniek Committed by Me No Dev

Fix map() division by zero (#2848)

parent aae6f24a
......@@ -65,9 +65,12 @@ long random(long howsmall, long howbig)
return random(diff) + howsmall;
}
long map(long x, long in_min, long in_max, long out_min, long out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
long map(long x, long in_min, long in_max, long out_min, long out_max) {
long divisor = (in_max - in_min);
if(divisor == 0){
return -1; //AVR returns -1, SAM returns 0
}
return (x - in_min) * (out_max - out_min) / divisor + out_min;
}
unsigned int makeWord(unsigned int w)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment