Skip to content

Instantly share code, notes, and snippets.

@rajesh-scribbledata
Last active June 15, 2021 16:38
Show Gist options
  • Select an option

  • Save rajesh-scribbledata/19fc5d482dea647da7870f5bc9af3d21 to your computer and use it in GitHub Desktop.

Select an option

Save rajesh-scribbledata/19fc5d482dea647da7870f5bc9af3d21 to your computer and use it in GitHub Desktop.
Julia Ramanujan Approximation for Pi
using Core: BigInt
using Base: Int64, Float64
function fact(n::BigInt)
if n <=1 return 1 end
return n * fact(n-1)
end
println(fact(12))
function ramanujan_approximation(max_k::BigInt)
constant = 2*sqrt(2) / 9801
val::Float64 = 0
for k in 0:max_k
iteration::Float64 = (fact(4*k) * (1103 + 26390*k)) / (fact(k)^4 * 396^(4*k) )
val += iteration
end
return (constant * val)
end
onebypi = ramanujan_approximation(2)
println(onebypi, " ", 1/onebypi)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment