dsfds656545
2015-04-28 06:50
浏览 237
已采纳

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?

图片转代码服务由CSDN问答提供 功能建议

在我的用例中,我想知道如何在Go中实现以下Java代码

  BigInteger base = new BigInteger(“ 16”); 
int指数= 1; 
BigInteger a = base.pow(指数);  // 16 ^ 1 = 16 
   
 
 

我可以导入 math / big 包并创建大整数,但无法 在Go中执行 Pow()函数。 另外,我在Go doc 中找不到该函数。 \ n

我是否必须为bigint实现自己的 Pow()版本? 有人可以帮我吗?

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

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

    打赏 评论

相关推荐 更多相似问题