Opened 10 years ago

Closed 10 years ago

Last modified 10 years ago

#8160 closed Bugs (fixed)

multiprecision: Number is not assigned after dividing zero by something.

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

#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
using boost::multiprecision::cpp_int;

int main()
{
    cpp_int a = 1;
    a = 0/cpp_int("1");
    std::cout << "a = " << a << "\n"; // a = 1
    return 0;
}

divide.hpp: line 341 says All the limbs in x are zero, so is the result:

However, result is not assigned to zero.

Attachments (1)

fix.patch (494 bytes ) - added by Stepan Podoskin <stepik-777@…> 10 years ago.
patch "boost/multiprecision"

Download all attachments as: .zip

Change History (7)

by Stepan Podoskin <stepik-777@…>, 10 years ago

Attachment: fix.patch added

patch "boost/multiprecision"

comment:1 by Stepan Podoskin <stepik-777@…>, 10 years ago

Summary: multiprecision: Number is not assinned after dividing zero by something.multiprecision: Number is not assigned after dividing zero by something.

comment:2 by John Maddock, 10 years ago

Confirmed.

comment:3 by John Maddock, 10 years ago

Resolution: fixed
Status: newclosed

(In [83128]) Fix bug in division of zero. Document and add tests. Fixes #8160.

comment:4 by Stepan Podoskin <stepik-777@…>, 10 years ago

I just want to note that comparison with zero here isn't necessary.

There is:

   if((r_order == 0) && (*pr == 0))

And few lines below:

   if((r_order == 0) && (*pr < y))

There is no reason to treat zero as some special value, it will be handled by second if, so lines 339-345 can be simply removed.

comment:5 by John Maddock, 10 years ago

Um.. clearly the bug I have at present has eaten my brains away :-(

Will fix shortly, thanks for your patience!

comment:6 by John Maddock, 10 years ago

(In [83153]) Better fix for #8160. Refs #8160.

Note: See TracTickets for help on using tickets.