Boost.Math 円周率を取得する

C++標準では、三角関数のためのsin(), cos()関数などは用意されているのに、なぜか円周率を取得するための関数や定数が用意されていません。VC++GCCはM_PIというマクロを提供していますが、汎用的ではないです。
Boost.Mathには、円周率を取得するためのboost::math::constants::pi()関数が用意されています。Boostが使える環境ならこれを使えばよさそうですね。

#include <iostream>
#include <limits>
#include <boost/math/constants/constants.hpp>

int main ()
{
    double pi = boost::math::constants::pi<double>();

    std::cout.precision(std::numeric_limits<double>::max_digits10);
    std::cout << pi << std::endl;
}
3.1415926535897931

Numeric Constants - Boost Math Library


追記:
Boost逆引きリファレンスにも書いておきました。
数学 - Boost逆引きリファレンス