mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
update book code
This commit is contained in:
30
eBook/examples/chapter_9/big.go
Normal file
30
eBook/examples/chapter_9/big.go
Normal file
@@ -0,0 +1,30 @@
|
||||
// big.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"math"
|
||||
"math/big"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
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)
|
||||
// Here are some calculations with bigInts:
|
||||
rm := big.NewRat(math.MaxInt64, 1956)
|
||||
rn := big.NewRat(-1956, math.MaxInt64)
|
||||
ro := big.NewRat(19, 56)
|
||||
rp := big.NewRat(1111, 2222)
|
||||
rq := big.NewRat(1, 1)
|
||||
rq.Mul(rm, rn).Add(rq, ro).Mul(rq, rp)
|
||||
fmt.Printf("Big Rat: %v\n", rq)
|
||||
}
|
||||
/* Output:
|
||||
Big Int: 43492122561469640008497075573153004
|
||||
Big Rat: -37/112
|
||||
*/
|
Reference in New Issue
Block a user