Boost.GeomertyとBoost.Ratioがtrunkにマージされた

Boost 1.47あたりに入るのかな?
Ratioはユーザーコードでは使わないと思うからいいとして、Boost.Geometryにはいろいろ便利なのが入ってそうです。


まず、円周率。M_PIが非標準なので、あるとうれしい。

#include <iostream>
#include <boost/geometry/util/math.hpp>

namespace bg = boost::geometry;

int main()
{
    const double pi = bg::math::pi<double>();
    std::cout << pi << std::endl;
}
3.14159

しかし、円周率は元々Boost.Mathにあったようです。Geometryはそれをラップしてるだけですね。


次に浮動小数点数の比較。

#include <boost/assert.hpp>
#include <boost/geometry/util/math.hpp>

namespace bg = boost::geometry;

int main()
{
    double a = 3.14;
    double b = 3.14;

    BOOST_ASSERT(bg::math::equals(a, b));
}

equals内部では、浮動小数点数かどうかで処理を分岐させてます。


幾何学的なコードをあまり書かない人でも、このあたりは使えるとうれしいんじゃないかと思います。