dsfds656545 2015-04-28 06:50 采纳率: 0%
浏览 412
已采纳

Go中的bigint.pow(a)等效于什么?

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

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

I am able to import the math/big package and create big integers, but not able to do Pow() function in Go. Also I don't find the function in the Go doc.

Do I have to implement my own version of Pow() for bigint? Could anyone help me on this?

  • 写回答

1条回答 默认 最新

  • douao8204 2015-04-28 06:54
    关注

    Use Exp with m set 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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?