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