[英]Golang, math/big: what is the max value of *big.Int
* big.Int的最大值和* big.Rat的最大精度是多少 ?
以下是結構定義:
// 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
}
沒有明確的限制。 限制將是您的記憶,或理論上,最大陣列大小(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)
}
(如果你希望它足夠快地運行Go Playground, 使用小於100000
指數 )
問題不是最大尺寸,而是使用的內存和計算所花費的時間。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.