I believe id does; in your example
from_min = -10, from_max = 10, to_max = 1, to_min = 0.
This gives
to_max - to_min = 1, from_max - from_min = 20;
So using the formula
x -> (x - from_min) * (to_max - to_min) / (from_max - from_min) + to_min = (x - from_min) * 1 / 20 + 0 = (x - from_min) / 20
gives
-10 -> (-10 + 10) / 20 = 0 / 20, -9 -> (-9 + 10) / 20 = 1 / 20, 1 -> (1 + 10) / 20 = 11 / 20, 4 -> (4 + 10) / 20 = 14 / 20, 10 -> (10 + 10) / 20 = 20 / 20,
therefore, all obtained values ββare non-negative. In addition, an initial minimum of -10 displays to_min = 0 and an initial maximum of 10 displays to_max = 1. If this does not work in your implementation, check if you have mixed integral types and floating point types.
source share