File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
include/behaviortree_cpp/utils Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff 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:" +
You can’t perform that action at this time.
0 commit comments