$include_dir="/home/hyper-archives/boost/include"; include("$include_dir/msg-header.inc") ?>
From: Beman Dawes (beman_at_[hidden])
Date: 2000-11-19 17:36:08
At 09:57 PM 11/19/2000 +0000, Paul Moore wrote:
 >Good point. I missed this case. And thanks for the clear and detailed bug
 >report.
 >
 >I'd rather add a check as
 >
 >template <typename IntType>
 >rational<IntType>& rational<IntType>::operator/= (const 
rational<IntType>&
 >r)
 >{
 >    // Trap division by zero
 >    if (r.num == 0) throw bad_rational();
 >    // Avoid overflow and preserve normalization
 >    IntType gcd1 = gcd<IntType>(num, r.num);
 >    IntType gcd2 = gcd<IntType>(r.den, den);
 >    num = (num/gcd1) * (r.den/gcd2);
 >    den = (den/gcd2) * (r.num/gcd1);
 >    return *this;
 >}
 >
 >I.e., test at the top, on the pinciple of avoiding unnecessary work. Why
 >calculate two GCDs when you won't use them?
 >
 >A question - should this throw bad_rational() or is there a standard 
divide
 >by zero exception? (Couldn't find one in a brief glance in the 
standard...)
 >
 >Beman, could you add this or would you like me to send a complete
 >replacement rational.hpp?
CVS changed.  bad_rational() seems OK to me.  Paul, if you want write 
access to CVS, let me know.
It's always great when boost developers can respond promptly to bug 
reports.
Thanks,
--Beman