2013-07-10 07:02
浏览 1.0k

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

What is the max value of *big.Int and max precision of *big.Rat?

图片转代码服务由CSDN问答提供 功能建议

* big.Int 的最大值和 * big.Rat

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • duanmei1930 2013-07-10 07:10

    Here are the structure definitions :

    // 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

    There is no explicit limit. The limit will be your memory or, theoretically, the max array size (2^31 or 2^63, depending on your platform).

    If you have practical concerns, you might be interested by the tests made in http://golang.org/src/pkg/math/big/nat_test.go, for example the one where 10^100000 is benchmarked.

    And you can easily run this kind of program :

    package main
    import (
    func main() {
        verybig := big.NewInt(1)
        ten := big.NewInt(10)
        for i:=0; i<100000; i++ {
           verybig.Mul(verybig, ten)

    (if you want it to run fast enough for Go Playground, use a smaller exponent than 100000)

    The problem won't be the max size but the used memory and the time such computations take.

    点赞 打赏 评论

相关推荐 更多相似问题