Skip to content

Commit 1b9e0e2

Browse files
committed
fix warnings
1 parent aa085b7 commit 1b9e0e2

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

include/behaviortree_cpp/utils/convert_impl.hpp

+11-2
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,17 @@ inline void checkTruncation(const From& from)
9393
if constexpr(std::is_integral_v<From> && std::is_floating_point_v<To>)
9494
{
9595
// Check if value can be represented exactly in the target type
96-
constexpr auto max_exact = (1LL << std::numeric_limits<double>::digits) - 1;
97-
if(from > max_exact || from < -max_exact)
96+
constexpr uint64_t max_exact = (1LL << std::numeric_limits<double>::digits) - 1;
97+
bool doesnt_fit = false;
98+
if constexpr(!std::is_signed_v<From>)
99+
{
100+
doesnt_fit = static_cast<uint64_t>(from) > max_exact;
101+
}
102+
else
103+
{
104+
doesnt_fit = std::abs(static_cast<int64_t>(from)) > static_cast<int64_t>(max_exact);
105+
}
106+
if(doesnt_fit)
98107
{
99108
throw std::runtime_error("Loss of precision when converting a large integer number "
100109
"to floating point:" +

0 commit comments

Comments
 (0)