Golang,math/big:*big.Int的最大值是多少

Dmi*_*hin 16 biginteger go

*big.Int的最大值和*big.Rat的最大精度是多少

Den*_*ret 16

以下是结构定义:

// A Word represents a single digit of a multi-precision unsigned integer.
type Word uintptr

type nat []Word

type Int struct {
    neg bool // sign
    abs nat  // absolute value of the integer
}

type Rat struct {
    // To make zero values for Rat work w/o initialization,
    // a zero value of b (len(b) == 0) acts like b == 1.
    // a.neg determines the sign of the Rat, b.neg is ignored.
    a, b Int
}
Run Code Online (Sandbox Code Playgroud)

没有明确的限制.限制将是您的记忆,或理论上,最大阵列大小(2 ^ 31或2 ^ 63,具体取决于您的平台).


如果您有实际问题,可能会对http://golang.org/src/pkg/math/big/nat_test.go中的测试感兴趣,例如10 ^ 100000进行基准测试的测试.

你可以轻松地运行这种程序:

package main

import (
    "fmt"
    "math/big"
)

func main() {
    verybig := big.NewInt(1)
    ten := big.NewInt(10)
    for i:=0; i<100000; i++ {
       verybig.Mul(verybig, ten)
    }
    fmt.Println(verybig)
}
Run Code Online (Sandbox Code Playgroud)

(如果你希望它足够快地运行Go Playground,使用小于指数100000)

问题不是最大尺寸,而是使用的内存和计算所花费的时间.