Fixing -1/1 bug as per #37661

git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/lang/trunk@383487 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Henri Yandell 2006-03-06 07:29:57 +00:00
parent 9f4f79fe3f
commit cf56a79ee7
2 changed files with 4 additions and 0 deletions

View File

@ -909,6 +909,8 @@ public final class Fraction extends Number implements Serializable, Comparable {
toProperString = "0";
} else if (numerator == denominator) {
toProperString = "1";
} else if (numerator == -1 * denominator) {
toProperString = "-1";
} else if ((numerator>0?-numerator:numerator) < -denominator) {
// note that we do the magnitude comparison test above with
// NEGATIVE (not positive) numbers, since negative numbers

View File

@ -1334,5 +1334,7 @@ public class FractionTest extends TestCase {
f = Fraction.getFraction(-1, 1, Integer.MAX_VALUE);
assertEquals("-1 1/2147483647", f.toProperString());
assertEquals("-1", Fraction.getFraction(-1).toProperString());
}
}