blob: b2b6fad856e2d1cb1e97a04472e0b8a7841747ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
#include <math.h>
#include <stdint.h>
/*
* In order to correctly scale by fractions of 120 (used by
* wp_fractional_scale_v1), we need to bias the result before rounding.
*/
uint32_t scale_apply(uint32_t base, uint32_t scale)
{
return round(base * (scale / 120.) + 1e-6);
}
uint32_t scale_apply_inverse(uint32_t base, uint32_t scale)
{
return round(base * (120. / scale) + 1e-6);
}
|