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...