The $$n$$-th harmonic number is the sum \[\sum_{i=1}^{n}\frac{1}{i}\]
For smaller values of $$n$$ it is simple to just calculate this sum. However, if $$n$$ if very large, it can take up a lot of time. For larger values of $$n$$, it is better to use an approach that is easy to calculate. You can approach the harmonic numbers using the formula below: \[\ln(n) + \gamma + \frac{1}{2n} - \frac{1}{12n^2} + \frac{1}{120n^4}\]
Here, $$\ln$$ is the natural logarithm1. The $$\gamma$$ in the formula is the Euler-Mascheroni constant2 (not to be mistaken with the Euler number that is represented by $$e$$) and is about equal to 0.577215664901532.
Write a function harmonicExact that exactly calculates the $$n$$-th harmonic number. The function takes one argument: $$n$$.
Write a function harmonicApproach that makes an approached calculation of the $$n$$th harmonic number. The function takes one argument: $$n$$.
Write a function harmonic that exactly calculates the $$n$$-th harmonic number if $$n$$ is smaller than 100 and that makes a rough calculation for other values. The function takes one argument: $$n$$. Avoid unnecessary duplication of code.
>>> harmonicExact(10)
2.9289682539682538
>>> harmonicApproach(10)
2.9289682578955776
>>> harmonic(10)
2.9289682539682538