Boost logo

Boost :

From: David Abrahams (david.abrahams_at_[hidden])
Date: 2002-02-09 11:22:01


Somebody posted this to the SourceForge bugs page in January:

http://sourceforge.net/tracker/?func=detail&atid=107586&aid=504411&group_id=
7586

The definition of operator /= for class template
rational does not handle self divisions (as in r /=
r;) correctly:

num = (num/gcd1) * (r.den/gcd2);
den = (den/gcd2) * (r.num/gcd1);

This code should be changed to:

IntType rnum = r.num;
num = (num/gcd1) * (r.den/gcd2);
den = (den/gcd2) * (rnum/gcd1);

Another solution would be to add:

if(this == &r)

num = den = IntType(1);
return *this;
}

*---------------------------------------------------*
                  David Abrahams
      C++ Booster (http://www.boost.org)
      Pythonista (http://www.python.org)
  resume: http://users.rcn.com/abrahams/resume.html
          email: david.abrahams_at_[hidden]
*---------------------------------------------------*


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