Commit e61d704
Round scaled config values instead of truncating on cast (#1256)
User-entered decimals are stored as scaled integers, but the cast from
double to integer truncates. atof("0.0464") is 0.046399999999999996, so
* 10000.0 yields 463.99999999999994 and the price modifier is stored as
463 instead of 464.
68866 of the 999999 possible four-decimal price modifier values are
stored one unit too low this way. Switching from float to double in
a733365 barely moved that count (68886 before, 68866 after); it only
changed which values land just below the integer, and 0.0464 moved into
the broken set.
Round with lround() at every scaling site instead: price modifiers,
meter multipliers, Wi-Fi power, Vcc offset/multiplier/boot limit and the
day/month plot editor, both in the web form handler and in the config
file parser. The config file parser also still used toFloat() for the
Vcc values and the price modifier, so it kept the old truncation on
backup restore.
Reported in #1251
Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>1 parent f746899 commit e61d704
2 files changed
Lines changed: 23 additions & 21 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
2172 | 2173 | | |
2173 | 2174 | | |
2174 | 2175 | | |
2175 | | - | |
| 2176 | + | |
2176 | 2177 | | |
2177 | 2178 | | |
2178 | | - | |
| 2179 | + | |
2179 | 2180 | | |
2180 | 2181 | | |
2181 | | - | |
| 2182 | + | |
2182 | 2183 | | |
2183 | 2184 | | |
2184 | | - | |
| 2185 | + | |
2185 | 2186 | | |
2186 | 2187 | | |
2187 | 2188 | | |
| |||
2220 | 2221 | | |
2221 | 2222 | | |
2222 | 2223 | | |
2223 | | - | |
| 2224 | + | |
2224 | 2225 | | |
2225 | 2226 | | |
2226 | | - | |
| 2227 | + | |
2227 | 2228 | | |
2228 | 2229 | | |
2229 | | - | |
| 2230 | + | |
2230 | 2231 | | |
2231 | 2232 | | |
2232 | 2233 | | |
| |||
2339 | 2340 | | |
2340 | 2341 | | |
2341 | 2342 | | |
2342 | | - | |
| 2343 | + | |
2343 | 2344 | | |
2344 | 2345 | | |
2345 | 2346 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| |||
1386 | 1387 | | |
1387 | 1388 | | |
1388 | 1389 | | |
1389 | | - | |
1390 | | - | |
1391 | | - | |
1392 | | - | |
| 1390 | + | |
| 1391 | + | |
| 1392 | + | |
| 1393 | + | |
1393 | 1394 | | |
1394 | 1395 | | |
1395 | 1396 | | |
| |||
1405 | 1406 | | |
1406 | 1407 | | |
1407 | 1408 | | |
1408 | | - | |
| 1409 | + | |
1409 | 1410 | | |
1410 | 1411 | | |
1411 | 1412 | | |
| |||
1567 | 1568 | | |
1568 | 1569 | | |
1569 | 1570 | | |
1570 | | - | |
1571 | | - | |
1572 | | - | |
| 1571 | + | |
| 1572 | + | |
| 1573 | + | |
1573 | 1574 | | |
1574 | 1575 | | |
1575 | 1576 | | |
| |||
1684 | 1685 | | |
1685 | 1686 | | |
1686 | 1687 | | |
1687 | | - | |
| 1688 | + | |
1688 | 1689 | | |
1689 | 1690 | | |
1690 | 1691 | | |
| |||
2773 | 2774 | | |
2774 | 2775 | | |
2775 | 2776 | | |
2776 | | - | |
| 2777 | + | |
2777 | 2778 | | |
2778 | 2779 | | |
2779 | 2780 | | |
2780 | | - | |
| 2781 | + | |
2781 | 2782 | | |
2782 | 2783 | | |
2783 | 2784 | | |
| |||
2798 | 2799 | | |
2799 | 2800 | | |
2800 | 2801 | | |
2801 | | - | |
| 2802 | + | |
2802 | 2803 | | |
2803 | 2804 | | |
2804 | 2805 | | |
2805 | | - | |
| 2806 | + | |
2806 | 2807 | | |
2807 | 2808 | | |
2808 | 2809 | | |
| |||
0 commit comments