Opened 21 years ago

Closed 17 years ago

#35 closed Bugs (Fixed)

Self division wrong in template rational

Reported by: nobody Owned by: Jonathan Turkanis
Milestone: Component: None
Version: None Severity:
Keywords: Cc:

Description

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;
    }

Change History (1)

comment:1 by Markus Schöpflin, 17 years ago

Status: assignedclosed
Logged In: YES 
user_id=91733

See
http://cvs.sourceforge.net/viewcvs.py/boost/boost/boost/rational.hpp?r1=1.10&r2=1.11

Was fixed by this check-in in Feb 2002, therefore closed.
Note: See TracTickets for help on using tickets.