commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Christian Semrau (JIRA)" <j...@apache.org>
Subject [jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy
Date Mon, 06 Dec 2010 23:24:10 GMT

    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12968480#action_12968480
] 

Christian Semrau commented on LANG-663:
---------------------------------------

Even if both arguments are reduced, if the divisor has numerator Integer.MIN_VALUE, divideBy
may fail despite the quotient being representable with positive denominator.

{code:title=FractionTest.java|borderStyle=solid}
    public void testDivide() {
        // ...
        f1 = Fraction.getFraction(2, 3);
        f2 = Fraction.getFraction(Integer.MIN_VALUE, 3);
        f = f1.divideBy(f2);
        assertEquals(-1, f.getNumerator());
        assertEquals(-Integer.MIN_VALUE / 2, f.getDenominator());
{code} 


> org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy
> -----------------------------------------------------------------------------------------
>
>                 Key: LANG-663
>                 URL: https://issues.apache.org/jira/browse/LANG-663
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.math.*
>    Affects Versions: 3.0
>            Reporter: Christian Semrau
>            Priority: Minor
>
> The Fraction.multiplyBy and divideBy methods fail sometimes when the arguments are not
reduced.
> {code:title=FunctionTest.java|borderStyle=solid}
>     public void testMultiply() {
>         // ...
>         f1 = Fraction.getFraction(Integer.MAX_VALUE, Integer.MAX_VALUE);
>         f2 = Fraction.getFraction(42, 1);
>         f = f1.multiplyBy(f2);
>         assertEquals(42, f.getNumerator());
>         assertEquals(1, f.getDenominator());
>     public void testDivide() {
>         // ...
>         f1 = Fraction.getFraction(Integer.MAX_VALUE, Integer.MAX_VALUE);
>         f2 = Fraction.getFraction(42, 1);
>         f = f1.divideBy(f2);
>         assertEquals(1, f.getNumerator());
>         assertEquals(42, f.getDenominator());
> {code}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message