Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make sure eval_convert_to() do not terminate with super large number
this change is a follow-up of d51f2e9. it intends to address the exception thrown in a noexcept functon. a minimal reproducer looks like ```c++ int main() { std::string s = "32767456456456456456545678943512357658768763546575675"; boost::multiprecision::cpp_int num(s); std::cout << num.convert_to<float>() << std::endl; } ``` since boost 1.79, the code above terminates like ``` Program returned: 139 Program stderr terminate called after throwing an instance of 'boost::wrapexcept<std::domain_error>' what(): Error in function float_next<float>(float): Argument must be finite, but got inf Program terminated with signal: SIGSEGV ``` because `float_next_imp()` throws 'boost::wrapexcept<std::domain_error>' if the number is NAN of INF. and `eval_convert_to()` is marked as `noexcept(boost::multiprecision::detail::is_arithmetic<R>::value && std::numeric_limits<R>::has_infinity)`, but only `overflow_error` is ignored in the policy passed to `float_next()`. so, in this change, `std::domain_error` is ignored as well, so that ``num.convert_to<float>()` returns a NaN in this case. Refs boostorg#553 Signed-off-by: Kefu Chai <[email protected]>
- Loading branch information