Properly use typed math constants instead of impl. specific hacks
PI is not in the stdlib, neither is 1/pi, pi*2 and so on. Instead of relying on implementations providing these, use properly typed math constants. Main benefits: - portable and - returns constexpr, for compile-time computation References: - http://www.boost.org/doc/libs/1_60_0/libs/math/doc/html/math_toolkit/constants_intro.html - http://www.boost.org/doc/libs/1_60_0/libs/math/doc/html/math_toolkit/constants.html
This commit is contained in:
@@ -6,6 +6,8 @@
|
||||
#include <vector>
|
||||
#include <utility>
|
||||
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
namespace osrm
|
||||
{
|
||||
namespace engine
|
||||
@@ -23,8 +25,10 @@ struct NormalDistribution
|
||||
// FIXME implement log-probability version since its faster
|
||||
double density_function(const double val) const
|
||||
{
|
||||
using namespace boost::math::constants;
|
||||
|
||||
const double x = val - mean;
|
||||
return 1.0 / (std::sqrt(2. * M_PI) * standard_deviation) *
|
||||
return 1.0 / (std::sqrt(two_pi<double>()) * standard_deviation) *
|
||||
std::exp(-x * x / (standard_deviation * standard_deviation));
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "util/integer_range.hpp"
|
||||
|
||||
#include <boost/assert.hpp>
|
||||
#include <boost/math/constants/constants.hpp>
|
||||
|
||||
#include <cmath>
|
||||
|
||||
@@ -17,7 +18,7 @@ namespace engine
|
||||
namespace map_matching
|
||||
{
|
||||
|
||||
static const double log_2_pi = std::log(2. * M_PI);
|
||||
static const double log_2_pi = std::log(2. * boost::math::constants::pi<double>());
|
||||
static const double IMPOSSIBLE_LOG_PROB = -std::numeric_limits<double>::infinity();
|
||||
static const double MINIMAL_LOG_PROB = std::numeric_limits<double>::lowest();
|
||||
static const std::size_t INVALID_STATE = std::numeric_limits<std::size_t>::max();
|
||||
|
||||
Reference in New Issue
Block a user