Opened 5 years ago

Closed 5 years ago

#13347 closed Bugs (duplicate)

4.666662/0.666666 is not equal to 7

Reported by: anonymous Owned by: John Maddock
Milestone: To Be Determined Component: multiprecision
Version: Boost 1.65.0 Severity: Problem
Keywords: Cc:

Description

I expect to get 7 when I divide 4.666662/0.666666 using boost::multiprecision::cpp_dec_float_50 but I get false when I compare the result with 7. Here is the code:

#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>

int main()
{
	using boost::multiprecision::cpp_dec_float_50;
	cpp_dec_float_50 left("4.666662"), right("0.666666");
	cpp_dec_float_50 div_res = left/right, correct_div_res("7");
	std::cout << std::boolalpha << (div_res == correct_div_res) << std::endl;
}

Attachments (1)

main.cpp (326 bytes ) - added by anonymous 5 years ago.

Download all attachments as: .zip

Change History (6)

by anonymous, 5 years ago

Attachment: main.cpp added

comment:1 by anonymous, 5 years ago

I build the test with clang 4.0 on Ubuntu 16.04:

$ clang++-4.0 -g -I ../include  --std=c++1z main.cpp 
$ ./a.out                                           
false

comment:2 by anonymous, 5 years ago

Building with --std=c++11 gives the same wrong result:

$ clang++-4.0 -g -I ../include  --std=c++11 main.cpp
$ ./a.out                                           
false

comment:3 by anonymous, 5 years ago

Version: Boost 1.63.0Boost 1.65.0

Boost version is 1.65.1

comment:4 by John Maddock, 5 years ago

We know: cpp_dec_float does not perform rounding, and has internal guard digits, both of which will cause this behaviour.

comment:5 by John Maddock, 5 years ago

Resolution: duplicate
Status: newclosed

Duplicates #11178

Note: See TracTickets for help on using tickets.