You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by "Phil Steitz (JIRA)" <ji...@apache.org> on 2011/01/15 18:48:45 UTC

[jira] Issue Comment Edited: (MATH-475) MathUtils.equals(double, double, double) does not agree with Javadoc

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

Phil Steitz edited comment on MATH-475 at 1/15/11 12:48 PM:
------------------------------------------------------------

Very interesting example.  How do you come up with this stuff, Sebb?  :)

I tend to agree with Gilles' view that if if a and b are not distinguishable as doubles, we don't really have any confidence in the value of abs(a - b), so the short-circuit in the current code is better.  I would say just update the javadoc to make say something like

"Returns true if the values are indistinguishable as doubles or the difference between them is within the range of allowed error (inclusive)."

      was (Author: psteitz):
    Very interesting example.  How do you come up with this stuff, Sebb?  :)

I tend to agree with Gilles' view that if if a and b are not distinguishable as doubles, we don't really have any confidence in the value of abs(a - b), so the short-circuit in the current code is better.  I would say just update the javadoc to make say something like

"Returns true if there is no double value strictly between the arguments or the difference between them is within the range of allowed error (inclusive)."
  
> MathUtils.equals(double, double, double) does not agree with Javadoc
> --------------------------------------------------------------------
>
>                 Key: MATH-475
>                 URL: https://issues.apache.org/jira/browse/MATH-475
>             Project: Commons Math
>          Issue Type: Bug
>            Reporter: Sebb
>
> MathUtils.equals(double, double, double) does not agree with its Javadoc.
> The Javadoc says:
> "Returns true if both arguments are equal or within the range of allowed error (inclusive)."
> However the following test fails:
> {code}
> double top=1.7976931348623184E16;
> double pen=1.7976931348623182E16;
> double diff=Math.abs(top-pen);
> assertTrue(MathUtils.equals(top, pen, 1.0)); // OK - implies the difference is <= 1.0
> assertTrue("expected < 1.0, but was: "+diff,diff <= 1.0); // reports: expected < 1.0, but was: 2.0
> {code}
> This discrepancy is because the equals(double, double, double) method also checks to see if the numbers are within one ULP of each other.
> Either the Javadoc needs to be corrected, or the code needs to be corrected to drop the ULP comparison.

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


Re: [jira] Issue Comment Edited: (MATH-475) MathUtils.equals(double, double, double) does not agree with Javadoc

Posted by Phil Steitz <ph...@gmail.com>.
On Sat, Jan 15, 2011 at 8:32 PM, Gilles Sadowski
<gi...@harfang.homelinux.org> wrote:
> Hi.
>
> On Sat, Jan 15, 2011 at 12:48:45PM -0500, Phil Steitz (JIRA) wrote:
>>
>>     [ https://issues.apache.org/jira/browse/MATH-475?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12982118#action_12982118 ]
>>
>> Phil Steitz edited comment on MATH-475 at 1/15/11 12:48 PM:
>> ------------------------------------------------------------
>>
>> Very interesting example.  How do you come up with this stuff, Sebb?  :)
>>
>> I tend to agree with Gilles' view that if if a and b are not distinguishable as doubles, we don't really have any confidence in the value of abs(a - b), so the short-circuit in the current code is better.  I would say just update the javadoc to make say something like
>>
>> "Returns true if the values are indistinguishable as doubles or the difference between them is within the range of allowed error (inclusive)."
>>
>>       was (Author: psteitz):
>>     Very interesting example.  How do you come up with this stuff, Sebb?  :)
>>
>> I tend to agree with Gilles' view that if if a and b are not distinguishable as doubles, we don't really have any confidence in the value of abs(a - b), so the short-circuit in the current code is better.  I would say just update the javadoc to make say something like
>>
>> "Returns true if there is no double value strictly between the arguments or the difference between them is within the range of allowed error (inclusive)."
>
> Just to be sure that we agree on the semantics of "equals": The latter
> description ("there is no double value strictly between the arguments")
> seems more representative of the code. Indeed, 2 successive floating point
> numbers _are_ distinguishable, but "equals" will nevertheless return true on
> the ground that any real number within the interval could be mapped to
> either of the two floating point numbers.
>
Sorry I got the second version of the comment wrong.  You are right
that the current impl of equals identifies two consecutive doubles.

Phil

>
> Gilles
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
> For additional commands, e-mail: dev-help@commons.apache.org
>
>

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


Re: [jira] Issue Comment Edited: (MATH-475) MathUtils.equals(double, double, double) does not agree with Javadoc

Posted by Gilles Sadowski <gi...@harfang.homelinux.org>.
Hi.

On Sat, Jan 15, 2011 at 12:48:45PM -0500, Phil Steitz (JIRA) wrote:
> 
>     [ https://issues.apache.org/jira/browse/MATH-475?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12982118#action_12982118 ] 
> 
> Phil Steitz edited comment on MATH-475 at 1/15/11 12:48 PM:
> ------------------------------------------------------------
> 
> Very interesting example.  How do you come up with this stuff, Sebb?  :)
> 
> I tend to agree with Gilles' view that if if a and b are not distinguishable as doubles, we don't really have any confidence in the value of abs(a - b), so the short-circuit in the current code is better.  I would say just update the javadoc to make say something like
> 
> "Returns true if the values are indistinguishable as doubles or the difference between them is within the range of allowed error (inclusive)."
> 
>       was (Author: psteitz):
>     Very interesting example.  How do you come up with this stuff, Sebb?  :)
> 
> I tend to agree with Gilles' view that if if a and b are not distinguishable as doubles, we don't really have any confidence in the value of abs(a - b), so the short-circuit in the current code is better.  I would say just update the javadoc to make say something like
> 
> "Returns true if there is no double value strictly between the arguments or the difference between them is within the range of allowed error (inclusive)."

Just to be sure that we agree on the semantics of "equals": The latter
description ("there is no double value strictly between the arguments")
seems more representative of the code. Indeed, 2 successive floating point
numbers _are_ distinguishable, but "equals" will nevertheless return true on
the ground that any real number within the interval could be mapped to
either of the two floating point numbers.


Gilles

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