hthang1988 / arduino

Automatically exported from code.google.com/p/arduino
0 stars 0 forks source link

map() truncation of integral results is confusing. #288

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
For example, map(x, 0, 100, 0, 1) returns 0 for x from 0 to 99, whereas one 
might expect 50-100 to yield 1.  This could be corrected by changing the 
function's calculation to:

(x - in_min) * (out_max - out_min + 1) / (in_max - in_min + 1) + out_min

Or by clarifying the behavior and usage in the documentation (e.g. explaining 
that you want to use the just past the range you're interested in).

Original issue reported on code.google.com by dmel...@gmail.com on 11 Jul 2010 at 9:22

GoogleCodeExporter commented 9 years ago
Also, see: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257716581/all and 
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1278362349

Original comment by dmel...@gmail.com on 11 Jul 2010 at 9:22