Modify

Opened 16 years ago

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

Attachments (0)

Change History (1)

comment:1 Changed 12 years ago by Markus Schöpflin

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.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Jonathan Turkanis.
The resolution will be deleted.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.