[Rd] identical(0, -0)
(Ted Harding)
Ted.Harding at manchester.ac.uk
Fri Aug 7 15:49:54 CEST 2009
On 07-Aug-09 11:07:08, Duncan Murdoch wrote:
> Martin Maechler wrote:
>>>>>>> William Dunlap <wdunlap at tibco.com>
>>>>>>> on Thu, 6 Aug 2009 15:06:08 -0700 writes:
>> >> -----Original Message----- From:
>> >> r-help-bounces at r-project.org
>> >> [mailto:r-help-bounces at r-project.org] On Behalf Of
>> >> Giovanni Petris Sent: Thursday, August 06, 2009 3:00 PM
>> >> To: milton.ruser at gmail.com Cc: r-help at r-project.org;
>> >> Daniel.Gerlanc at geodecapital.com Subject: Re: [R] Why is 0
>> >> not an integer?
>> >>
>> >>
>> >> I ran an instant experiment...
>> >>
>> >> > typeof(0) [1] "double" > typeof(-0) [1] "double" >
>> >> identical(0, -0) [1] TRUE
>> >>
>> >> Best, Giovanni
>>
>> > But 0.0 and -0.0 have different reciprocals
>>
>> >> 1.0/0.0
>> > [1] Inf
>> >> 1.0/-0.0
>> > [1] -Inf
>>
>> > Bill Dunlap TIBCO Software Inc - Spotfire Division wdunlap
>> > tibco.com
>>
>> yes. {finally something interesting in this boring thread !}
>> ---> diverting to R-devel
>>
>> In April, I've had a private e-mail communication with John
>> Chambers [father of S, notably S4, which also brought identical()]
>> and Bill about the topic,
>> where I had started suggesting that R should be changed such
>> that
>> identical(-0. , +0.)
>> would return FALSE.
>> Bill did mention that it does so for (newish versions of) S+
>> and that he'd prefer that, too,
>> and John said
>>
>> >> I agree on having a preference for a bitwise comparison for
>> >> identical()---that's what the name means after all. But since
>> >> someone implemented the numerical case as the C == it's probably
>> >> going to be more hassle than it's worth to change it. But we
>> >> should make the implementation clear in the documentation.
>>
>> so in principle, we all agreed that R's identical() should be
>> changed here, namely by using something like memcmp() instead
>> of simple '==' , however we haven't bothered to actually
>> *implement* this change.
>>
>> I am currently testing a patch which would lead to
>> identical(0, -0) return FALSE.
>>
> I don't think that would be a good idea. Other expressions besides
> "-0"
> calculate the zero with the negative sign bit, e.g. the following
> sequence:
>
> pos <- 1
> neg <- -1
> zero <- 0
> y <- zero*pos
> z <- zero*neg
> identical(y, z)
>
> I think most R users would expect the last expression there to be
> TRUE based on the previous two lines, given that pos and neg both
> have finite values. In a simple case like this y == z would be a
> better test to use, but if those were components of a larger
> structure, identical() is all we've got, and people would waste a
> lot of time tracking down why structures differing only in the
> sign of zero were not identical, even though every element tested
> equal.
>
> Duncan Murdoch
>> Martin Maechler, ETH Zurich
My own view of this is that there may in certain cirumstances be an
interest in distinguishing between 0 and (-0), yet normally most
users will simply want to compare the numerical values.
Therefore I am in favour of revising identical() so that it can so
distinguish; but also of taking the opportunity to give it a parameter
say
identical(x,y,sign.bit=FALSE)
so that the default behaviour would be to see 0 and (-0) as identical,
but with sign.bit=TRUE it would see the difference.
However, I put this forward in ignorance of
a) Any difficulties that this may present in re-coding identical();
b) Any complications that may arise when applying this new form
to complex objects.
Ted.
--------------------------------------------------------------------
E-Mail: (Ted Harding) <Ted.Harding at manchester.ac.uk>
Fax-to-email: +44 (0)870 094 0861
Date: 07-Aug-09 Time: 14:49:51
------------------------------ XFMail ------------------------------
More information about the R-devel
mailing list