Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Boost::multiprecision::sqrt(1) return 0?

Boost::multiprecision::sqrt(1) seems to return 0

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/number.hpp>
#include <iostream>

using std::cout;
using std::endl;

int main() {
   namespace mp = boost::multiprecision;
   mp::cpp_int i(1); 
   cout << "i == " << i << endl;
   cout << "mp::sqrt(i) == " << mp::sqrt(i) << endl;
}

Output:
i == 1
mp::sqrt(i) == 0

I expect that sqrt(1) == 1.

I get the same results on coliru and on my local installation with gcc and Boost 1.62. Does this happen to others? Am I missing something or is this a bug?

like image 440
Chad Avatar asked Oct 30 '16 20:10

Chad


1 Answers

Yes, this is definitely a bug. It was reported to the Boost bug tracker 3 days ago as ticket #12559.

like image 181
kirbyfan64sos Avatar answered Oct 12 '22 12:10

kirbyfan64sos