You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Alex Herbert (Jira)" <ji...@apache.org> on 2026/04/16 10:04:00 UTC

[jira] [Resolved] (NUMBERS-207) Fraction and BigFraction compareTo incorrect for negative values

     [ https://issues.apache.org/jira/browse/NUMBERS-207?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Alex Herbert resolved NUMBERS-207.
----------------------------------
    Fix Version/s: 1.3
       Resolution: Fixed

> 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
>             Fix For: 1.3
>
>
> 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)