Skip to content

Instantly share code, notes, and snippets.

@rdp
Created June 21, 2016 15:54
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rdp/20e6414f01708242c7a44331b07ab9db to your computer and use it in GitHub Desktop.
Save rdp/20e6414f01708242c7a44331b07ab9db to your computer and use it in GitHub Desktop.
golang use rational numbers example
package main
import "math/big"
import "fmt"
import "time"
func main() {
fmt.Printf("Hello, world.\n")
start := time.Now()
r := new(big.Rat)
for i := 0; i < 10000000; i++ {
r.Add(r, big.NewRat(1, 1))
}
elapsed := time.Since(start)
fmt.Printf(" took %s %d", elapsed, r)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment