The Term-inator: Pi edition
Out parameters in C++

In C++, you should almost never use out parameters (variables taken by reference and used to return a value from a function), you can read this excellent article by Eric Niebler. There are few cases where out parameters can make sense:


When you want your return to be fast. And even then, return value optimization and move semantics may still be faster.
When you have several output values. For example, you want to assign a value to a function and return whether it succeeded:

bool assign(int from, int&amp; to)
{
    if (from != 0)
    {
        to = from;
        return true;
    }
    return false;
}


But even for this situation, there are better solutions such as boost:optional to return both a value and whether it succeeded or not. And if you need several error values, use exceptions. And if you need to actually return several values, you general want to pack them into a dedicated struct or a std::tuple.
Input-output parameters: sometimes, you want to take a parameter, read from it, and then write to it again. That is still a valid use case (but these are not strict out parameters anymore).


In your case, it seems that getSanitizedDouble could simply return the read long double instead of having an out parameter.

Type correctness

You could improve your type correctness:


That's also a naming issue: I don't expect a function named getSanaitzeDouble to return a long double, but to return a double.
The literal used in the expression long double pi = 0.; is incorrect: 0. is a double. The correct long double literal should be 0.0L. We could also use 0.0l, but the l suffix is really too close to 1 not to be dangerous.


Order your includes

Alphabetical order is something you should always use to order your headers (at least in a logical group of headers). That allows a faster search to check whether some headers has already been included:

#include &lt;cctype&gt;
#include &lt;cmath&gt;
#include &lt;iostream&gt;
#include &lt;limits&gt;