# Learning Julia - Ramanujan Approximation for Pi

**URL:** <https://discourse.julialang.org/t/learning-julia-ramanujan-approximation-for-pi/62959>\
**Category:** New to Julia\
**Created:** [June 15, 2021, 4:05pm UTC](https://discourse.julialang.org/t/learning-julia-ramanujan-approximation-for-pi/62959 "2021-06-15T16:05:10Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![aiexplorations](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiexplorations/32/26117_2.png) [@aiexplorations](https://discourse.julialang.org/u/aiexplorations)\
**Post date:** [June 15, 2021, 4:05pm UTC](https://discourse.julialang.org/t/learning-julia-ramanujan-approximation-for-pi/62959/1 "2021-06-15T16:05:10Z")

</div>

Hi all,

I’m new to Julia and am learning the ropes thanks to the MIT course and books like Think Julia. I’m working through a few simple problems to start with, and wanted some help with this one.

Implementing Ramanujan’s approximation for pi - it is essentially a serial computation that I’ve implemented using a loop in Julia. This approach returns Inf / 0.0 when I exceed max\_k = 5.

Can someone help me with why it doesn’t work for cases where max\_k \> 5?

> <https://gist.github.com/rajesh-scribbledata/19fc5d482dea647da7870f5bc9af3d21>

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [June 15, 2021, 4:10pm UTC](https://discourse.julialang.org/t/learning-julia-ramanujan-approximation-for-pi/62959/2 "2021-06-15T16:10:47Z")

</div>

Try looking at the results of the `fact` function as you increase `n`. You will see that something goes wrong.

This is due to the fact that standard Julia integers (`Int64`) have a maximum possible size that they can store. A solution to this is to use `BigInt` instead.

A better solution is to rewrite your code (if possible) so that you don’t actually need to compute the whole factorial.

---

<div class="post-metadata">

**Author:** ![aiexplorations](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/aiexplorations/32/26117_2.png) [@aiexplorations](https://discourse.julialang.org/u/aiexplorations)\
**Post date:** [June 15, 2021, 4:44pm UTC](https://discourse.julialang.org/t/learning-julia-ramanujan-approximation-for-pi/62959/3 "2021-06-15T16:44:12Z")

</div>

Thanks, I did look through the fact() function and I have changed the types there and elsewhere to BigInt. It helped me push the thing to max\_k = 5.

However, I realized that the results for this series converge very close to what we know to be pi even with k=3. Therefore going to k\>5 may be unnecessary - but I’m still reading up on this.

Thanks for helping me with this question! 🙂
