--- rational.hpp.orig 2006-02-19 04:31:25.000000000 -0500 +++ rational.hpp 2006-02-19 03:41:58.000000000 -0500 @@ -390,21 +390,21 @@ IntType zero(0); // If the two values have different signs, we don't need to do the - // expensive calculations below. We take advantage here of the fact + // expensive division. We take advantage of the fact // that the denominator is always positive. - if (num < zero && i >= zero) // -ve < +ve - return true; - if (num >= zero && i <= zero) // +ve or zero is not < -ve or zero - return false; - // Now, use the fact that n/d truncates towards zero as long as n and d - // are both positive. + // Otherwise, use the fact that n/d truncates towards zero as long as n + // and d are both non-negative. // Divide instead of multiplying to avoid overflow issues. Of course, // division may be slower, but accuracy is more important than speed... - if (num > zero) - return (num/den) < i; + if (num < zero) { + if (i >= zero) + return true; + return -i < (-num/den); + } else if (i <= zero) + return false; else - return -i < (-num/den); + return (num/den) < i; } template