How about an ijulia notebook of 101 ways to compute pi in Julia, ideally 
with accompanying graphics? 

On Sunday, 8 March 2015 13:16:26 UTC, Johan Sigfrids wrote:
>
> Because calling out to mpfr is cheating here is a implementation of 
> Gauss-Legendre in Julia calculating Pi to the desired number of digits 
> (Still relying on BigFloats though). 
>
> function gaussLegendrePi(d::Integer)
>     prec = get_bigfloat_precision()
>     set_bigfloat_precision(iceil(d*log(10)/log(2))+10)
>     n = iceil(log2(d))
>     a = BigFloat(1)
>     b = a / sqrt(BigFloat(2))
>     t = a / BigFloat(4)
>     x = a
>     while n > 0
>         y = a
>         a = (a + b) / 2
>         b = sqrt(b * y)
>         t = t - x * (y - a)^2
>         x = 2 * x
>         n -= 1
>     end
>     p = ((a + b)^2) / (4 * t)
>     println(string(p)[1:d+1])
>     set_bigfloat_precision(prec)
>     nothing
> end
>
> I haven't done any validation beyond checking that it and Mathematica 
> agree on the millionth digit of Pi. 
>

Reply via email to