Skip to content

Instantly share code, notes, and snippets.

@jbagley jbagley/LeibnizPiApprox
Last active Aug 29, 2015

Embed
What would you like to do?
My first attempt at using Swift in an Xcode playground
// Gregory-Leibniz approximation of π
// See https://gist.github.com/jbagley/9558879 for C implementation
var factor = -1.0
var piAccumulation = 4.0
var denom = 3.0
// If using in a playground beware this many iterations, try 2500 instead.
for i in 1…500000
{
piAccumulation += factor * (4.0 / denom)
denom += 2.0;
factor *= -1.0;
}
println(piAccumulation)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.