commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ntysdd (JIRA)" <j...@apache.org>
Subject [jira] [Comment Edited] (MATH-1196) FastMath.round (like Math.round) returns surprising results for some arguments
Date Fri, 06 Mar 2015 10:48:38 GMT

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

ntysdd edited comment on MATH-1196 at 3/6/15 10:48 AM:
-------------------------------------------------------

Not so easy.
Java 7 still wrong.

{code:xml}
    public void test() {
        final double x = 4503599627370497.0; // x = Math.pow(2, 52) + 1;
        Assert.assertEquals("4503599627370497", new BigDecimal(x).toString());
        Assert.assertTrue(x == Math.rint(x));
        Assert.assertTrue(x == FastMath.round(x));
        Assert.assertTrue(x == Math.round(x));
    }
{code}


was (Author: ntysdd):
Not so easy.
Still wrong.

{code:xml}
    public void test() {
        final double x = 4503599627370497.0; // x = Math.pow(2, 52) + 1;
        Assert.assertTrue(x == Math.rint(x));
        Assert.assertTrue(x == FastMath.round(x));
    }
{code}

> FastMath.round (like Math.round) returns surprising results for some arguments
> ------------------------------------------------------------------------------
>
>                 Key: MATH-1196
>                 URL: https://issues.apache.org/jira/browse/MATH-1196
>             Project: Commons Math
>          Issue Type: Bug
>    Affects Versions: 3.4.1
>            Reporter: Phil Steitz
>
> The first assertion in the test case below succeeds, but the second fails
> {code}
>  /*
>      * http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6430675
>      */
>     @Test
>     public void testRoundDown() {
>         final double x = 0x1.fffffffffffffp-2;
>         Assert.assertTrue(x < 0.5d);
>         Assert.assertEquals(0, FastMath.round(x));
>     }
> {code}
> This is being tracked as a JDK (actually spec) bug here:
> http://bugs.java.com/bugdatabase/view_bug.do?bug_id=6430675



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message