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:
Emmanuel T Odeke 2020-12-20 10:41:59 -08:00 committed by GitHub
parent 25bb17db8a
commit 21716644d4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 4 deletions

View File

@ -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)
}