2017-05-06 128 views
0

我需要爲我的項目使用big.Ints,因爲我使用的數字超出了int64限制。找到big.Int的平方根

通過定期整型,你可以用它方:

math.Sqrt(value) 

但我不知道如何做到這一點,但big.Ints。

任何幫助將不勝感激,

感謝

+0

https://golang.org /pkg/math/big/#Int.Sqrt – ain

+0

@ain你能回答一個例子嗎?謝謝 – MaxCodes

+0

@MaxCodes我添加了這個例子。 –

回答

1

使用https://golang.org/pkg/math/big/#Int.Sqrt在big.int接口給出

package main 

import (
    "fmt" 
    "math/big" 
) 

func main() { 
    var Str = `10000000000000000000000000000000000000000000000000000` 
    bigInt := &big.Int{} 
    value, _ := bigInt.SetString(Str, 10) 
    sqrt := bigInt.Sqrt(value) 
    fmt.Println(sqrt) 
} 

輸出:

100000000000000000000000000