commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Sebb (JIRA)" <j...@apache.org>
Subject [jira] Commented: (MATH-471) MathUtils.equals(double, double) does not work properly for floats
Date Fri, 14 Jan 2011 16:11:45 GMT

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

Sebb commented on MATH-471:
---------------------------

Many of the double-only methods work OK with widened float parameters.

Where this is not the case, we either need to fix the discrepancy (as per this JIRA) or document
the restriction.

I don't see the point of separating the utilities into two different classes, but if the consensus
is that we should, then we need to make sure that the same methods are present in both, even
if the double method works perfectly well, otherwise it would be even more confusing for users
(where do I find the method?).

But I think the main issue is that having a separate class would force users to *edit and
recompile* to take advantage of any fixes such as this one.

> MathUtils.equals(double, double) does not work properly for floats
> ------------------------------------------------------------------
>
>                 Key: MATH-471
>                 URL: https://issues.apache.org/jira/browse/MATH-471
>             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))));
// FAILS
> 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.


Mime
View raw message