You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Christian Semrau (JIRA)" <ji...@apache.org> on 2010/12/07 00:16:25 UTC

[jira] Created: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Christian Semrau (JIRA)" <ji...@apache.org>.
    [ 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.


[jira] Closed: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell closed LANG-663.
------------------------------

    Resolution: Fixed

svn ci -m "Adding note that this has overflow issues and pointing to BigFraction" src/main/java/org/apache/commons/lang3/math/Fraction.java 
Sending        src/main/java/org/apache/commons/lang3/math/Fraction.java
Transmitting file data .
Committed revision 1059747.


> 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
>             Fix For: 3.0
>
>
> 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.


[jira] Updated: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Henri Yandell updated LANG-663:
-------------------------------

    Fix Version/s: 3.0

Need to resolve before 3.0 release.

> 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
>             Fix For: 3.0
>
>
> 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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Henri Yandell (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12981317#action_12981317 ] 

Henri Yandell commented on LANG-663:
------------------------------------

Resolution sounds like it'll be pointing to Math BigFraction in the javadoc of Lang Fraction.

> 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
>             Fix For: 3.0
>
>
> 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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Christian Semrau (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12976662#action_12976662 ] 

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

I favor having only one Fraction class, preferably in Math.

In MATH-251, the solution to overflow is using a larger number range (BigInteger). This issue (LANG-663) and  LANG-662 mention spurious overflows that need not occur when using int: The overflows mentioned here can be avoided. Of course, there are many overflows that cannot be avoided, and therefore BigFraction was a valueable addition.

> 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
>             Fix For: 3.0
>
>
> 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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Stephen Colebourne (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12976866#action_12976866 ] 

Stephen Colebourne commented on LANG-663:
-----------------------------------------

Commons Math is a specialist library, Lang is a general purpose one. Fraction is definitely a general purpose concept, and so shoudl remain in Lang. Of course any bugs should be fixed, but remembering the general-purpose, rather than mathematical, focus.

> 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
>             Fix For: 3.0
>
>
> 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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Sebb (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12976883#action_12976883 ] 

Sebb commented on LANG-663:
---------------------------

I agree - Lang needs to keep its existing basic mathematical (mainly arithmetical) classes.

> 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
>             Fix For: 3.0
>
>
> 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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Christian Semrau (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12968478#action_12968478 ] 

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

These methods fail to reduce their arguments. This may be due to the commons-math Fraction (which seems to be the source) is always in reduced form. But commons-lang Fraction is not always reduced, and so multiplyBy must reduce its arguments, before cross-reducing the two arguments.


> 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.


[jira] Commented: (LANG-663) org.apache.commons.lang3.math.Fraction does not always succeed in multiplyBy and divideBy

Posted by "Christian Semrau (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/jira/browse/LANG-663?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12976735#action_12976735 ] 

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

Oh, and seeing that method Fraction.addSub (both in Lang and Math) does all it can to ensure that spurious overflow is prevented (by using a BigInteger for an intermediate value), I wonder if the overflow of 2 / 3 divided by MIN_VALUE / 3 would be acceptable (in the Math version!), when it can be prevented too.

> 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
>             Fix For: 3.0
>
>
> 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.