Golang,数学/大 : what is the max value of *big. Int

标签 go biginteger

*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,use a smaller exponent than 100000)

问题不在于最大大小,而在于使用的内存和此类计算所花费的时间。

关于Golang,数学/大 : what is the max value of *big. Int,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17564335/

相关文章:

java - 从 int 值创建 BigInteger 实例的最有效方法是什么?

javascript - 如何在 JavaScript 中将字符串转换为 bigInt

java.math.BigInteger,pow方法只接受int

go - 为什么我的 “done” channel 随机关闭?

parsing - 如何解析方法声明?

file - io.Copy() 的稀疏文件很大

go - 如何绕过 dgrijalva/jwt-go 中的 cve-2020-26160 漏洞?

c - 如何在 C/C++ 中获得大数的精确二进制表示?

java - JDK RSACore.priCrypt 如何工作以及 getBlindingRandomPair 是什么意思?

go - Hugo - 呈现自定义内容类型的 ListView