Modify

Ticket #8126 (closed Bugs: fixed)

Opened 14 months ago

Last modified 14 months ago

multiprecision, incorrect sign

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

Change History

comment:1 Changed 14 months ago by Stepan Podoskin <stepik-777@…>

  • Owner set to johnmaddock
  • Component changed from None to multiprecision

comment:2 Changed 14 months ago by johnmaddock

  • Status changed from new to closed
  • Resolution set to fixed

(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 14 months 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 14 months ago by johnmaddock

  • Status changed from closed to reopened
  • Resolution fixed deleted

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 14 months ago by johnmaddock

  • Status changed from reopened to closed
  • Resolution set to fixed

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

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


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

 
Note: See TracTickets for help on using tickets.