[
https://issues.apache.org/jira/browse/NUMBERS-207?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17935770#comment-17935770
]
Richard Mullender commented on NUMBERS-207:
-------------------------------------------
Looks like it, thanks! That was very quick
Out of interest, do you know if there's any reason why we use the more
complicated comparison method here and not the [one used by the lang3 Fraction
class|https://github.com/apache/commons-lang/blob/master/src/main/java/org/apache/commons/lang3/math/Fraction.java#L572-L584]?
> Fraction and BigFraction compareTo incorrect for negative values
> ----------------------------------------------------------------
>
> Key: NUMBERS-207
> URL: https://issues.apache.org/jira/browse/NUMBERS-207
> Project: Commons Numbers
> Issue Type: Bug
> Components: fraction
> Affects Versions: 1.2
> Reporter: Richard Mullender
> Priority: Major
>
> Both `Fraction` and `BigFraction` display incorrect `compareTo` behaviour
> when comparing negative fractions against one another.
> See the below test class:
> {code:java}
> public class FractionTest {
> @Test
> public void testFraction() {
> var fraction1 = org.apache.commons.numbers.fraction.Fraction.of(-10,
> 1);
> var fraction2 = org.apache.commons.numbers.fraction.Fraction.of(-5, 1);
>
> assert fraction1.compareTo(fraction2) < 0;
> }
>
> @Test
> public void testBigFraction() {
> var fraction1 =
> org.apache.commons.numbers.fraction.BigFraction.of(-10, 1);
> var fraction2 = org.apache.commons.numbers.fraction.BigFraction.of(-5,
> 1);
>
> assert fraction1.compareTo(fraction2) < 0;
> }
>
> @Test
> public void testApacheLang3() {
> var fraction1 =
> org.apache.commons.lang3.math.Fraction.getFraction(-10, 1);
> var fraction2 = org.apache.commons.lang3.math.Fraction.getFraction(-5,
> 1);
>
> assert fraction1.compareTo(fraction2) < 0;
> }
> }
> {code}
>
> Out of these three tests, only Lang3's Fraction passes. The other two tests
> (fraction.Fraction and fraction.BigFraction) fail.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)