Initialize a big.int value

Hello, I need to initialize a big.int value with some integer that has 400 digits. However when my code is like

var N big.Int
	N = 2014096878945207511726700485783442547915321782072704356103039129009966793396141985086509455102260403208695558793091390340438867513766123418942845301603261911930567685648626153212566300102683464717478365971313989431406854640516317519403149294308737302321684840956395183222117468443578509847947119995373645360710979599471328761075043464682551112058642299370598078702810603300890715874500584758146849481

I get a “constant too large” error. Can someone tell me the best way to initialize it?
Thanks

2 Likes

You can use SetString/2 method

4 Likes

Here is an example
https://play.golang.org/p/QhrZzhpZMI6

package main
import (
	"fmt"
	"math/big"
)

func main() {
	i := new(big.Int)
	Num := "2014096878945207511726700485783442547915321782072704356103039129009966793396141985086509455102260403208695558793091390340438867513766123418942845301603261911930567685648626153212566300102683464717478365971313989431406854640516317519403149294308737302321684840956395183222117468443578509847947119995373645360710979599471328761075043464682551112058642299370598078702810603300890715874500584758146849481"
	i.SetString(Num, 10)
	fmt.Println(i)
	fmt.Println(Num)
}
3 Likes

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.