From 27965c1551c572af10c7dc7a3d7de3c8f6854e3e Mon Sep 17 00:00:00 2001 From: Mike Date: Thu, 21 Feb 2019 09:41:53 +0000 Subject: [PATCH] Fix `map()` bug in `WMath.cpp` (#1636) --- Sming/Wiring/WMath.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Sming/Wiring/WMath.cpp b/Sming/Wiring/WMath.cpp index 6dfd927480..bef41bd102 100644 --- a/Sming/Wiring/WMath.cpp +++ b/Sming/Wiring/WMath.cpp @@ -80,11 +80,11 @@ long random(long howsmall, long howbig) long map(long x, long in_min, long in_max, long out_min, long out_max) { - long divisor = (in_max - in_min) + out_min; + 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; + return ( (x - in_min) * (out_max - out_min) / divisor ) + out_min; }