Logo

Programming-Idioms

History of Idiom 66 > diff from v330 to v331

Edit summary for version 331 by programming-idioms.org:
[Go] +DocURL

Version 330

2019-10-28, 20:50:29

Version 331

2019-12-22, 21:05:20

Idiom #66 Big integer exponentiation

Calculate the result z of x power n, where x is a big integer and n is a positive integer.

Idiom #66 Big integer exponentiation

Calculate the result z of x power n, where x is a big integer and n is a positive integer.

Imports
import "math/big"
Imports
import "math/big"
Code
nb := big.NewInt(int64(n))
var z big.Int
z.Exp(x, nb, nil)
Code
nb := big.NewInt(int64(n))
var z big.Int
z.Exp(x, nb, nil)
Comments bubble
Exponentiation is already implemented in package math/big.
Comments bubble
Exponentiation is already implemented in package math/big.
Doc URL
https://golang.org/pkg/math/big/#Int.Exp
Demo URL
https://play.golang.org/p/98o-x4T4od
Demo URL
https://play.golang.org/p/98o-x4T4od