Hi,

I was trying to run all checks on commons-number and found findbug is
failing in Precision.java[544] FE_FLOATING_POINT_EQUALITY

{code}
case BigDecimal.ROUND_HALF_EVEN : {
            double fraction = unscaled - Math.floor(unscaled);
            if (fraction > 0.5) {
                unscaled = Math.ceil(unscaled);
            } else if (fraction < 0.5) {
                unscaled = Math.floor(unscaled);
            } else {
                // The following equality test is intentional and needed
for rounding purposes
                if (Math.floor(unscaled) / 2.0 ==
Math.floor(Math.floor(unscaled) / 2.0)) { // even // failing here.
                //
                    unscaled = Math.floor(unscaled);
                } else { // odd
                    unscaled = Math.ceil(unscaled);
                }
            }
            break;
        }
{code}

Error is :
Test for floating point equality in
org.apache.commons.numbers.core.Precision.roundUnscaled(double, double,
int) [Of Concern(15), High confidence]

Fix:
Replace equality check with below:
if (Math.abs((Math.floor(unscaled) / 2.0) -
(Math.floor(Math.floor(unscaled) / 2.0))) < .0000001)

we have couple of similar issues in code.
Let me know if we have better alternative, else will submit code.

Regards,
Amey

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@commons.apache.org
For additional commands, e-mail: dev-h...@commons.apache.org

Reply via email to