[jira] [Created] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

classic Classic list List threaded Threaded
12 messages Options
Reply | Threaded
Open this post in threaded view
|

[jira] [Created] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
---------------------------------------------------------------------------------

                 Key: MATH-744
                 URL: https://issues.apache.org/jira/browse/MATH-744
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 2.2
            Reporter: Thundre
         Attachments: site.patch

The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.

I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)

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

Thundre updated MATH-744:
-------------------------

    Attachment: site.patch

Patch file for the fraction package.
               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/MATH-744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13206491#comment-13206491 ]

Gilles commented on MATH-744:
-----------------------------

Thanks for fixing this.
Would you mind adding a unit test that demonstrates the fix?

               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/MATH-744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13206514#comment-13206514 ]

Thundre commented on MATH-744:
------------------------------

I don't have the test classes working in Eclipse, so I can't do it there.  Here's a main method that demonstrates.  (10^401+1)/(10^400) is just a smidgen more than 10.

    public static void main(String args[]) {
        double x = new BigFraction(BigInteger.TEN.pow(401).add(BigInteger.ONE),
                BigInteger.TEN.pow(400)).doubleValue();
        System.out.println(x);
        System.exit(0);
    }
               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Thundre updated MATH-744:
-------------------------

    Attachment: test.patch

I figured out my problem with junit.  Here's a test case.
               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch, test.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Thundre updated MATH-744:
-------------------------

    Comment: was deleted

(was: I don't have the test classes working in Eclipse, so I can't do it there.  Here's a main method that demonstrates.  (10^401+1)/(10^400) is just a smidgen more than 10.

    public static void main(String args[]) {
        double x = new BigFraction(BigInteger.TEN.pow(401).add(BigInteger.ONE),
                BigInteger.TEN.pow(400)).doubleValue();
        System.out.println(x);
        System.exit(0);
    })
   

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch, test.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/MATH-744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13206520#comment-13206520 ]

Thundre commented on MATH-744:
------------------------------

I noticed that floatValue() has the same bug.  Stand by for more patches.
               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch, test.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Thundre updated MATH-744:
-------------------------

    Attachment: src.patch

Patch for fixes to BigFraction.doubleValue() and floatValue(), and junit tests.
               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: site.patch, src.patch, test.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Thundre updated MATH-744:
-------------------------

    Attachment:     (was: site.patch)
   

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: src.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Updated] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Thundre updated MATH-744:
-------------------------

    Attachment:     (was: test.patch)
   

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: src.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Commented] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

    [ https://issues.apache.org/jira/browse/MATH-744?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13206532#comment-13206532 ]

Gilles commented on MATH-744:
-----------------------------

Sorry to be picky, but it is better to avoid clumping many tests in the same test function, especially if they check different things.
In this case, you could create a new test method, e.g. "testDoubleValueForLargeNumeratorAndDenominator".
Also, in addition to checking that the result is not NaN, you should check that the result is the expected value.
Thanks for your contribution.

               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>         Attachments: src.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

       
Reply | Threaded
Open this post in threaded view
|

[jira] [Resolved] (MATH-744) BigFraction.doubleValue() returns Double.NaN for large numerators or denominators

ASF GitHub Bot (Jira)
In reply to this post by ASF GitHub Bot (Jira)

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

Gilles resolved MATH-744.
-------------------------

       Resolution: Fixed
    Fix Version/s: 3.0

Fix committed in revision 1243912.
Added unit tests.

               

> BigFraction.doubleValue() returns Double.NaN for large numerators or denominators
> ---------------------------------------------------------------------------------
>
>                 Key: MATH-744
>                 URL: https://issues.apache.org/jira/browse/MATH-744
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 2.2
>            Reporter: Thundre
>             Fix For: 3.0
>
>         Attachments: src.patch
>
>
> The current implementation of doubleValue() divides numerator.doubleValue() / denominator.doubleValue().  BigInteger.doubleValue() fails for any number greater than Double.MAX_VALUE.  So if the user has 308-digit numerator or denominator, the resulting quotient fails, even in cases where the result would be well inside Double's range.
> I have a patch to fix it, if I can figure out how to attach it here I will.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira