Modify

Opened 4 years ago

Closed 4 years ago

#8126 closed Bugs (fixed)

multiprecision, incorrect sign

Reported by: Stepan Podoskin <stepik-777@…> 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;
}

Attachments (0)

Change History (5)

comment:1 Changed 4 years ago by Stepan Podoskin <stepik-777@…>

Component: Nonemultiprecision
Owner: set to John Maddock

comment:2 Changed 4 years ago by John Maddock

Resolution: fixed
Status: newclosed

(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.

comment:3 Changed 4 years ago by Stepan Podoskin <stepik-777@…>

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 Changed 4 years ago by John Maddock

Resolution: fixed
Status: closedreopened

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 Changed 4 years ago by John Maddock

Resolution: fixed
Status: reopenedclosed

(In [83080]) Fix bug in subtraction of a limb_type. Fix bug in division/modulus algorithms that results in incorrect sign when source and destination overlap. Tweak performance of GCD algorithms. Add test cases for bug reports. Fixes #8133. Fixes #8126.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain John Maddock.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.