Last active
February 23, 2016 23:02
-
-
Save pgburt/fc944ea48c766cc62ec7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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