Skip to content

Commit

Permalink
Cleanup of BinaryInteger/power(_:) (#53).
Browse files Browse the repository at this point in the history
We only need to combine the multiplier's error indicator once at the end.
  • Loading branch information
oscbyspro committed Aug 3, 2024
1 parent 8199370 commit 27585fb
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Sources/CoreKit/BinaryInteger+Exponentiation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,17 @@ extension BinaryInteger {

exponentiation: while true {
if Bool(exponent.lsb) {
power = power.times(multiplier)
power = power.times(multiplier.value)
}

exponent = exponent.down(Shift(unchecked: Count(unchecked: 1)))
if exponent.isZero { break }

if exponent.isZero {
return (power).veto(multiplier.error)
}

multiplier = multiplier.squared()
}

return power // as Fallible<Self>
}

//=------------------------------------------------------------------------=
Expand Down

0 comments on commit 27585fb

Please sign in to comment.