commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <>
Subject [jira] Commented: (MATH-471) MathUtils.equals(double, double) does not work properly for floats
Date Thu, 13 Jan 2011 03:05:45 GMT


Sebb commented on MATH-471:

Just had a thought:

I don't think the exactly same code can be added to 2.x, because the semantics of some of
the double methods has changed.
It would be confusing if floats behaved differently from doubles!

So I propose to rework the fix for 2.x to preserve the deprecated behaviour and deprecated


> MathUtils.equals(double, double) does not work properly for floats
> ------------------------------------------------------------------
>                 Key: MATH-471
>                 URL:
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Sebb
>         Attachments: Math471.patch
> MathUtils.equals(double, double) does not work properly for floats.
> There is no equals(float,float) so float parameters are automatically promoted to double.
However, that is not necessarily appropriate, given that the ULP for a double is much smaller
than the ULP for a float.
> So for example:
> {code}
> double oneDouble = 1.0d;
> assertTrue(MathUtils.equals(oneDouble, Double.longBitsToDouble(1 + Double.doubleToLongBits(oneDouble))));
// OK
> float oneFloat = 1.0f;
> assertTrue(MathUtils.equals(oneFloat, Float.intBitsToFloat(1 + Float.floatToIntBits(oneFloat))));
> float  f1 = 333.33334f;
> double d1 = 333.33334d;
> assertTrue(MathUtils.equals(d1, f1)); // FAILS
> {code}
> I think the equals() methods need to be duplicated with the appropriate changes for floats
to avoid any problems with the promotion of floats.

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message