mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
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)
|
- Matter update hierarchy of plugins (#19915)
|
||||||
- NeoPool ``NPHydrolysis`` percent and unit (#19924)
|
- NeoPool ``NPHydrolysis`` percent and unit (#19924)
|
||||||
- Thermostat JSON index from 0 to 1 (#20011)
|
- Thermostat JSON index from 0 to 1 (#20011)
|
||||||
|
- Fixed `changeUIntScale` for linearity when expanding range
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Scripter timer issue (#19914)
|
- 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;
|
uint32_t result;
|
||||||
if ((num - from_min) < 0x8000L) { // no overflow possible
|
if ((num - from_min) < 0x8000L) { // no overflow possible
|
||||||
uint32_t numerator = ((num - from_min) * 2 + 1) * (to_max - to_min + 1);
|
if (to_max - to_min > from_max - from_min) {
|
||||||
result = numerator / ((from_max - from_min + 1) * 2) + to_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
|
} else { // no pre-rounding since it might create an overflow
|
||||||
uint32_t numerator = (num - from_min) * (to_max - to_min + 1);
|
uint32_t numerator = (num - from_min) * (to_max - to_min + 1);
|
||||||
result = numerator / (from_max - from_min) + to_min;
|
result = numerator / (from_max - from_min) + to_min;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user