This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug libstdc++/47913] New: [C++0x] improve ratio_add to overflow less often
- From: "marc.glisse at normalesup dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 27 Feb 2011 13:12:56 +0000
- Subject: [Bug libstdc++/47913] New: [C++0x] improve ratio_add to overflow less often
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47913
Summary: [C++0x] improve ratio_add to overflow less often
Product: gcc
Version: 4.6.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P3
Component: libstdc++
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: marc.glisse@normalesup.org
ratio_add currently computes something like:
gcd=gcd(den1,den2)
num=num1*(den2/gcd)+num2*(den1/gcd)
den=den1*(den2/gcd)
gcd2=gcd(num,den)
num/=gcd2
den/=gcd2
In cases where gcd2 is not 1, the computation may overflow whereas the final
result would fit. Even without that, it is possible that one or both of the
terms added in num are too large but their sum is not.
As a quality of implementation issue, it would be nice to reduce those cases a
bit. But that comes far far behind the ratio_less improvement described in PR
42622.