osrm-backend/include/util/json_util.hpp

28 lines
544 B
C++
Raw Permalink Normal View History

#ifndef JSON_UTIL_HPP
#define JSON_UTIL_HPP
2016-01-02 11:13:44 -05:00
#include "osrm/json_container.hpp"
#include <cmath>
#include <limits>
namespace osrm::util::json
{
// Make sure we don't have inf and NaN values
template <typename T> T clamp_float(T d)
{
if (std::isnan(d) || std::numeric_limits<T>::infinity() == d)
{
return std::numeric_limits<T>::max();
}
if (-std::numeric_limits<T>::infinity() == d)
{
return std::numeric_limits<T>::lowest();
}
return d;
}
2022-12-20 12:00:11 -05:00
} // namespace osrm::util::json
2016-01-05 10:51:13 -05:00
#endif // JSON_UTIL_HPP