What is equivalent for bigint.pow (a) in Go?

In my use case, I would like to know how the following Java code will be implemented in Go

BigInteger base = new BigInteger("16");
int exponent = 1;
BigInteger a = base.pow(exponent); //16^1 = 16

I can import the package math/bigand create large integers, but could not execute the function Pow()in Go. Also, I did not find the function in the document <.

Should I implement my own version Pow()for bigint? Can someone help me with this?

+4
source share
1 answer

Use Expwith mset to nil.

var i, e = big.NewInt(16), big.NewInt(2)
i.Exp(i, e, nil)
fmt.Println(i) // Prints 256

Playground: http://play.golang.org/p/0QFbNHEsn5

+7
source

Source: https://habr.com/ru/post/1585041/


All Articles