1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2025-01-18 12:52:44 +01:00
19032: sys/analog_util/dac_util: fix truncation bug r=maribu a=Enoch247

### Contribution description

From the commit message:

>  In `dac_util_map(...)` the expression `((value - min) * UINT16_MAX)` was cast to a 16 bit unsigned, then divided by `(max - min)`. This means that anytime `(value - min) != 0` the numerator was truncated prior to being divided and then returned.
> 
>  This patch modifies the expression so that the downcast to 16 bits is performed as the last operation.


### Testing procedure

Should be verifiable by simply analyzing the code.

### Issues/PRs references

none known


Co-authored-by: Joshua DeWeese <jdeweese@primecontrols.com>
This commit is contained in:
bors[bot] 2022-12-10 15:27:39 +00:00 committed by GitHub
commit bc0dcb9a36
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -24,7 +24,7 @@
uint16_t dac_util_map(int value, int min, int max)
{
return (uint16_t)((value - min) * UINT16_MAX) / (max - min);
return (uint16_t)(((value - min) * UINT16_MAX) / (max - min));
}
uint16_t dac_util_mapf(float value, float min, float max)