types: unconditionally divide by 2 because of integer truncation ⌊x/2⌋ (#8202)
Simplify the code in Dec.Power to unconditionally divide by 2, since: x /= 2 is the same result for both even and odd integers, and produces the floor of the result of x/2 -> ⌊x/2⌋: 99/2 ~> 49.5 ⌊49.5⌋ = 49 98/2 ~> 49.0 ⌊49.0⌋ = 49 aka "integer truncation". Fixes #7924
This commit is contained in:
parent
25bb17db8a
commit
21716644d4
|
@ -394,12 +394,10 @@ func (d Dec) Power(power uint64) Dec {
|
|||
tmp := OneDec()
|
||||
|
||||
for i := power; i > 1; {
|
||||
if i%2 == 0 {
|
||||
i /= 2
|
||||
} else {
|
||||
if i%2 != 0 {
|
||||
tmp = tmp.Mul(d)
|
||||
i = (i - 1) / 2
|
||||
}
|
||||
i /= 2
|
||||
d = d.Mul(d)
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue