go的math.big用法

点击查看代码
package main

import (
	"fmt"
	"math/big"
)

func genFibLst(n int) (a []string) {
	n1 := big.NewInt(1)
	n2 := big.NewInt(1)
	fmt.Printf("n1=%s, n2=%s, n1.string=%s\n",n1,n2,n1.String())
	for n > 0 {
		a = append(a, n1.String())
		tmp := n1.Add(n1, n2)
		fmt.Printf("n1=%s, n2=%s, a=%v,tmp=%s \n",n1,n2,a,tmp)
		n1 = n2
		n2 = tmp
		n--
	}
	return a
}

func main() {
	lst := genFibLst(10)
	for index, val := range lst {
		fmt.Println(index + 1, val)
	}
}
posted @ 2022-02-27 14:01  ty1539  阅读(127)  评论(0编辑  收藏  举报