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;
}
Note:
See TracTickets
for help on using tickets.
