Opened 10 years ago
Closed 10 years ago
#8126 closed Bugs (fixed)
multiprecision, incorrect sign
| Reported by: | Owned by: | John Maddock | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | multiprecision |
| Version: | Boost 1.53.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
This program outputs "-1" instead of "1".
Tested on 32-bit machine with GCC 4.7.2 and MSVC 2010 (boost 1.53.0).
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;
int main()
{
cpp_int a("-4294967296");
cpp_int b("4294967296");
cpp_int c("-1");
std::cout << (a/b)*c << '\n'; // prints "1" (correct)
a = (a/b)*c;
std::cout << a; // prints "-1" (incorrect)
return 0;
}
Change History (5)
comment:1 by , 10 years ago
| Component: | None → multiprecision |
|---|---|
| Owner: | set to |
comment:2 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
comment:3 by , 10 years ago
You fixed that case but here is another one that stil doesn't work.
cpp_int a("-26607734784073568386365259775");
cpp_int b("8589934592");
a = a/b;
std::cout << a; // outputs 3097548007973652377
comment:4 by , 10 years ago
| Resolution: | fixed |
|---|---|
| Status: | closed → reopened |
Not only that one actually, there's a whole bunch of divide and and modulus operators that don't behave correctly when source and destination are the same.
Testing some new fixes now...
comment:5 by , 10 years ago
| Resolution: | → fixed |
|---|---|
| Status: | reopened → closed |
Note:
See TracTickets
for help on using tickets.

(In [83060]) Fix sign of division in cpp_int when the values are small enough to fit in a double_limb_type. Add test cases for above. Fixes #8126.