One of the powers of Julia is its flexibility in applying its type system. In this recipe, we explain how to write flexible code that can adjust to the required type, using the example of approximating π.
Approximating pi using partial series sums
Getting ready
Approximation of π is a long-standing problem in mathematics. You can find many formulas for its calculation at http://mathworld.wolfram.com/PiFormulas.html.Â
One of the more interesting methods is the use of an infinite sum of terms 
forÂ
, ranging from zero to infinity. The denominator in each summed fraction is a double factorial (see http://mathworld.wolfram.com/DoubleFactorial.html or https://en.wikipedia...