duangeli1334 2013-07-10 07:02
浏览 2090
已采纳

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

What is the max value of *big.Int and max precision of *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 (
        "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)
    }
    

    (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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办