Skip to content

Instantly share code, notes, and snippets.

@pgburt
Last active February 23, 2016 23:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgburt/fc944ea48c766cc62ec7 to your computer and use it in GitHub Desktop.
Save pgburt/fc944ea48c766cc62ec7 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math"
"math/big"
//"github.com/iron-io/iron_go/worker"
)
const begin int = 1
const end int = 10
func CalcNumerator(num int) int64 {
odd := math.Mod(float64(num), 2)
if (odd == 1) {
return -1
}
return 1 // otherwise, it's even
}
func main() {
sum := big.NewRat(0, 1)
for i := begin; i <= end; i++ {
leibnizNum := CalcNumerator(i)
leibnizDen := int64(2 * i + 1)
leibnizRat := big.NewRat(leibnizNum, leibnizDen)
sum.Add(sum, leibnizRat)
// fmt.Println("run number is: ", n)
// fmt.Println("sum is: ", sum)
}
fmt.Println("Final sum is: ", sum)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment