GO 数字运算

 

大整数运算

// bigint project main.go
package main
 
import (
    "fmt"
    "math"
    "math/big"
)
 
func main() {
    // Here are some calculations with bigInts:
    im := big.NewInt(math.MaxInt64)
    in := im
    io := big.NewInt(1956)
    ip := big.NewInt(1)
    ip.Mul(im, in).Add(ip, im).Div(ip, io)
    fmt.Printf("Big Int: %v\n", ip)
    iq := big.NewInt(10000)
    ip.Mod(ip, iq)
    fmt.Printf("Big Int: %v\n", ip)
}

 

 

大整数比较

enough := bigWeiBalance.Cmp(bigWeiValue)

原来,big.Int 类自带cmp方法

 

返回 1:前面的big.Int 实例大于cmp方法big.Int 参数

返回 0:前面的big.Int 实例等于cmp方法big.Int 参数

 

posted @ 2020-11-12 10:42  方诚  阅读(461)  评论(0编辑  收藏  举报