mirror of https://github.com/arendst/Tasmota.git
Fixed `changeUIntScale` for linearity when expanding range (#20089)
This commit is contained in:
parent
a693c28d07
commit
1cd13d7f66
|
@ -19,6 +19,7 @@ All notable changes to this project will be documented in this file.
|
|||
- Matter update hierarchy of plugins (#19915)
|
||||
- NeoPool ``NPHydrolysis`` percent and unit (#19924)
|
||||
- Thermostat JSON index from 0 to 1 (#20011)
|
||||
- Fixed `changeUIntScale` for linearity when expanding range
|
||||
|
||||
### Fixed
|
||||
- Scripter timer issue (#19914)
|
||||
|
|
|
@ -412,8 +412,13 @@ uint16_t changeUIntScale(uint16_t inum, uint16_t ifrom_min, uint16_t ifrom_max,
|
|||
|
||||
uint32_t result;
|
||||
if ((num - from_min) < 0x8000L) { // no overflow possible
|
||||
if (to_max - to_min > from_max - from_min) {
|
||||
uint32_t numerator = (num - from_min) * (to_max - to_min) * 2;
|
||||
result = ((numerator / (from_max - from_min)) + 1 ) / 2 + to_min;
|
||||
} else {
|
||||
uint32_t numerator = ((num - from_min) * 2 + 1) * (to_max - to_min + 1);
|
||||
result = numerator / ((from_max - from_min + 1) * 2) + to_min;
|
||||
}
|
||||
} else { // no pre-rounding since it might create an overflow
|
||||
uint32_t numerator = (num - from_min) * (to_max - to_min + 1);
|
||||
result = numerator / (from_max - from_min) + to_min;
|
||||
|
|
Loading…
Reference in New Issue