If we have an arbitrary double value f, another one v and a multiplication factor p, how can I snap the value f to the nearest v power of p?
Example:
- f = 3150.0
- v = 100.0
- p = 2
the multiplications will go like this
- 100 (
v) - 200 (multiplied by
p) - 400
- 800
- 1600
- 3200
...
f is closest to 3200.0 so the function should return 3200.0
There was actually a name for this, which I seem to have forgotten and maybe this is why I couldn't find such a function.