[Boost-bugs] [Boost C++ Libraries] #13101: multiplication overflow issue

Subject: [Boost-bugs] [Boost C++ Libraries] #13101: multiplication overflow issue
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2017-06-27 20:34:04


#13101: multiplication overflow issue
------------------------------+----------------------
 Reporter: ramey | Owner: dlwalker
     Type: Feature Requests | Status: new
Milestone: To Be Determined | Component: None
  Version: Boost 1.63.0 | Severity: Problem
 Keywords: |
------------------------------+----------------------
 The following code will result in erroneous output due to integer
 overflow.
 {{{
 rational x {1, INT_MAX};
 rational y {1, 2};
 rational z = x * y; // will result in error due to overflow
 }}}

 The relevant section of the library code - rational.hpp line 500 is

 {{{
 // Avoid overflow and preserve normalization
 IntType gcd1 = integer::gcd(num, r_den);
 IntType gcd2 = integer::gcd(r_num, den);
 num = (num/gcd1) * (r_num/gcd2);
 den = (den/gcd2) * (r_den/gcd1);
 }}}

 which, in spite of comment, does not implement any checking for overflow.
 The same argument applies to addition and likely other operations.
 Division does check for divide by zero and throws an exception.

 The documentation itself is kind of cagey on the issue. In spite of
 having opened this issue I'm not sure what I really want to ask for.
 Sorry about this. Longer term I would hope to see rational and multi
 precision integers not include any checking and permit safe integer do it.
 But of course I'm not there yet.

--
Ticket URL: <https://svn.boost.org/trac10/boost/ticket/13101>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-06-27 20:37:17 UTC