Opened 6 years ago
Closed 5 years ago
#12881 closed Bugs (duplicate)
Reducing the precision integer division in VS 2015 and above
| Reported by: | runc | Owned by: | John Maddock | 
|---|---|---|---|
| Milestone: | To Be Determined | Component: | multiprecision | 
| Version: | Boost 1.63.0 | Severity: | Problem | 
| Keywords: | Cc: | 
Description
The result of the following code is different in VS 2013 and VS 2015:
VS 2013 output "6"
VS 2015 output "5.9999999..9977"
#include <iostream>
#include <boost/multiprecision/cpp_dec_float.hpp>
int main()
{
    boost::multiprecision::cpp_dec_float_50 num = 180;
    boost::multiprecision::cpp_dec_float_50 res = num / 30;
    std::cout.precision(100);
    std::cout << res;
    std::getchar();
    return 0;
}
The difference is explained by the presence in the file "boost\multiprecision\detail\default_ops.hpp" 2 block of code with check
#if !BOOST_WORKAROUND(BOOST_MSVC, < 1900) ... #endif
  Note:
 See   TracTickets
 for help on using tickets.
    
Duplicates https://svn.boost.org/trac10/ticket/11178
Notwithstanding that this is annoying, it is also expected behaviour for division with cpp_dec_float. MSVC post 2015 actually goes via a more efficient code path that preserves the internal result of the division.