Subject: [Boost-bugs] [Boost C++ Libraries] #12559: sqrt for cpp_int_backend behaves incorrect for small argument values
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-10-27 09:51:04
#12559: sqrt for cpp_int_backend behaves incorrect for small argument values
-------------------------------------------+----------------------------
Reporter: Rüdiger Brünner <rbruenner@â¦> | Owner: johnmaddock
Type: Bugs | Status: new
Milestone: To Be Determined | Component: multiprecision
Version: Boost 1.62.0 | Severity: Problem
Keywords: multiprecision integer sqrt |
-------------------------------------------+----------------------------
The sqrt function for multiprecision integers does not work for small
values.
Using this code:
{{{
checked_int128_t int1;
for (int i = 10; i >= 0; i--)
{
int1 = i;
try
{
int1 = sqrt(int1);
std::cout << "sqrt(" << i << ") = " << int1 << std::endl;
}
catch (std::exception& ex)
{
std::cout << "sqrt(" << i << ") -> " << typeid(ex).name()
<< ": " << ex.what() << std::endl;
}
}
}}}
I get the following output:
{{{
sqrt(10) = 3
sqrt(9) = 3
sqrt(8) = 2
sqrt(7) = 2
sqrt(6) = 2
sqrt(5) = 2
sqrt(4) = 2
sqrt(3) -> class boost::exception_detail::clone_impl<struct
boost::exception_detail::error_info_injector<class std::overflow_error> >:
Unable to allocate sufficient storage for the value of the result: value
overflows the maximum allowable magnitude.
sqrt(2) -> class boost::exception_detail::clone_impl<struct
boost::exception_detail::error_info_injector<class std::overflow_error> >:
Unable to allocate sufficient storage for the value of the result: value
overflows the maximum allowable magnitude.
sqrt(1) = 0
sqrt(0) = 0
}}}
While sqrt(3) and sqrt(2) are raising an exception, sqrt(1) gives a wrong
result.
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/12559> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:20 UTC