Opened 17 years ago

Closed 13 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:


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 Changed 13 years ago by Markus Schöpflin

Status: assignedclosed
Logged In: YES 


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