Skip to content

Instantly share code, notes, and snippets.

@wdalmut
Created November 11, 2013 11:51
Show Gist options
  • Save wdalmut/7412092 to your computer and use it in GitHub Desktop.
Save wdalmut/7412092 to your computer and use it in GitHub Desktop.
package main
import(
"fmt"
"math"
)
func main() {
fmt.Printf("PI approx\n")
piValue := float64(0)
for i:=0; ;i++ {
piValue += pi(i)
if (i % 1e7 == 0) {
fmt.Printf("%v\n", piValue)
}
}
}
func pi(k int) float64 {
return 4 * (math.Pow(-1, float64(k)) / float64((2*k + 1)))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment