File tree Expand file tree Collapse file tree 1 file changed +6
-5
lines changed
include/behaviortree_cpp/utils Expand file tree Collapse file tree 1 file changed +6
-5
lines changed Original file line number Diff line number Diff line change @@ -93,15 +93,16 @@ 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- To as_float = static_cast <To>(from);
97- From back_conv = static_cast <From>(as_float);
98- if (back_conv != from)
96+ constexpr auto max_exact = (1LL << std::numeric_limits<double >::digits) - 1 ;
97+ if (from > max_exact || from < -max_exact)
9998 {
100- throw std::runtime_error (" Loss of precision in conversion to floating point" );
99+ throw std::runtime_error (" Loss of precision when converting a large integer number "
100+ " to floating point:" +
101+ std::to_string (from));
101102 }
102103 }
103104 // Handle floating point to integer
104- if constexpr (std::is_floating_point_v<From> && std::is_integral_v<To>)
105+ else if constexpr (std::is_floating_point_v<From> && std::is_integral_v<To>)
105106 {
106107 if (from > static_cast <From>(std::numeric_limits<To>::max ()) ||
107108 from < static_cast <From>(std::numeric_limits<To>::lowest ()) ||
You can’t perform that action at this time.
0 commit comments