Shift mapping math out of floating point
@@ -239,12 +239,12 @@ int64_t _lv_pow(int64_t base, int8_t exp)
* @param in min output range
* @param out max output range
*/
-LV_ATTRIBUTE_FAST_MEM int16_t _lv_map(int16_t x, float min_in, float max_in, float min, float max)
+LV_ATTRIBUTE_FAST_MEM int16_t _lv_map(int16_t x, int16_t min_in, int16_t max_in, int16_t min, int16_t max)
{
- float slope = (max - min) / (max_in - min_in);
- float bias = min - slope * min_in;
+ uint32_t slope = ((uint32_t)(max - min) * 1000) / (uint32_t)(max_in - min_in); /** times 1000 to avoid rounding errors*/
+ uint32_t bias = min - (slope * min_in) / 1000;
- return bias + slope * x;
+ return bias + (slope * x) / 1000;
}
/**********************
