big.go 666 B

123456789101112131415161718192021222324252627282930
  1. // big.go
  2. package main
  3. import (
  4. "math"
  5. "math/big"
  6. "fmt"
  7. )
  8. func main() {
  9. // Here are some calculations with bigInts:
  10. im := big.NewInt(math.MaxInt64)
  11. in := im
  12. io := big.NewInt(1956)
  13. ip := big.NewInt(1)
  14. ip.Mul(im, in).Add(ip, im).Div(ip, io)
  15. fmt.Printf("Big Int: %v\n", ip)
  16. // Here are some calculations with bigInts:
  17. rm := big.NewRat(math.MaxInt64, 1956)
  18. rn := big.NewRat(-1956, math.MaxInt64)
  19. ro := big.NewRat(19, 56)
  20. rp := big.NewRat(1111, 2222)
  21. rq := big.NewRat(1, 1)
  22. rq.Mul(rm, rn).Add(rq, ro).Mul(rq, rp)
  23. fmt.Printf("Big Rat: %v\n", rq)
  24. }
  25. /* Output:
  26. Big Int: 43492122561469640008497075573153004
  27. Big Rat: -37/112
  28. */