MCPcopy Create free account
hub / github.com/CovenantSQL/CovenantSQL / Exp

Function Exp

utils/big.go:212–225  ·  view source on GitHub ↗

Exp implements exponentiation by squaring. Exp returns a newly-allocated big integer and does not change base or exponent. The result is truncated to 256 bits. Courtesy @karalabe and @chfast.

(base, exponent *big.Int)

Source from the content-addressed store, hash-verified

210//
211// Courtesy @karalabe and @chfast.
212func Exp(base, exponent *big.Int) *big.Int {
213 result := big.NewInt(1)
214
215 for _, word := range exponent.Bits() {
216 for i := 0; i < wordBits; i++ {
217 if word&1 == 1 {
218 U256(result.Mul(result, base))
219 }
220 U256(base.Mul(base, base))
221 word >>= 1
222 }
223 }
224 return result
225}

Callers 1

TestExpFunction · 0.85

Calls 1

U256Function · 0.85

Tested by 1

TestExpFunction · 0.68