Closed br0kenpixel closed 10 months ago
I think it's easiest to show by example:
0.01 * 0.01 = 0.0001
; so a multiplication of two numbers of scale 2, needs a scale of 4
0.01 / 100 = 0.0001
; so a division of a number needs a scale that's larger by roughly the log_10
of the divisor.
So you have a scale of 2, the multiplication makes it 4, the division by a number with a log_10
of 4 increases it to 15 and there it stays.
I suppose the other way to show why it's needed is that the answer has 15 digits after the decimal place, so any smaller scale would have given an incorrect answer.
If you don't care for exact precision (where it can be obtained):
f32
or similar, orrescale
to the precision you needThanks! 😀
I have the following function:
Example usage:
Which gives:
I'm not sure if I missed something in the documentation, or it's a bug, but why does the scale change from 2 to 15?. Since all decimals have a scale of 2, I'd expect the result to also retain this scale. The only solution I found was adding
value.rescale(2)
before returningvalue
. Is this normal, or a bug?