You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "George Smith (JIRA)" <ji...@apache.org> on 2018/10/02 21:18:00 UTC

[jira] [Created] (MATH-1470) Precision.round(double...)'s use of Double.toString(x) rounds twice resulting in inaccuracy

George Smith created MATH-1470:
----------------------------------

             Summary: Precision.round(double...)'s use of Double.toString(x) rounds twice resulting in inaccuracy
                 Key: MATH-1470
                 URL: https://issues.apache.org/jira/browse/MATH-1470
             Project: Commons Math
          Issue Type: Bug
    Affects Versions: 3.6.1
            Reporter: George Smith


The use of Double.toString(x) in the creation of the BigDecimal used by the Precision.round(double...) methods introduces a rounding that can then generate incorrect results when the rounding is applied to the BigDecimal.  Whenever possible rounding should only be applied to the most accurate value available.  Switching the BigDecimal construction to use the double value directly resolves the problem.

 

This problem can be seen by running the main method of the com.altoros.floatingpoint.PrecisionProblem class in the repo hosted at: [https://github.com/Altoros/precision-problem]

 

George

 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)