Boost logo

Boost :

From: Jeff Paquette (paquette_at_[hidden])
Date: 2000-11-20 11:34:11


PMFJI, but did anyone else notice the fix went from (stylistic arguments
aside):

if (den == 0)

to

if (r.num == 0)
?

Shouldn't the correct fix be:
if (r.den == 0) throw bad_rational()

--
Jeff Paquette
paquette at mediaone.net
http://www.atnetsend.net
> -----Original Message-----
> From: Beman Dawes [mailto:beman_at_[hidden]]
> Sent: Sunday, November 19, 2000 5:36 PM
> To: boost_at_[hidden]; boost_at_[hidden]
> Subject: RE: [boost] Bug in boost/rational.hpp
>
>
> 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
>
>
>
>

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk