From savicky at cs.cas.cz  Wed Aug 12 18:20:13 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Wed, 12 Aug 2009 18:20:13 +0200
Subject: [Rd] identical(0, -0)
In-Reply-To: <19074.52084.426535.783434@lynne.math.ethz.ch>
References: <4A7D8E08.2070300@uottawa.ca> <20090810092141.GC10119@cs.cas.cz>
	<4A7FECCD.2010208@stats.uwo.ca>
	<353CA09D-6769-4F58-AC2C-B7AD2CF5DE0C@r-project.org>
	<4A802CB7.3030806@stats.uwo.ca> <4A804219.3080803@stats.uwo.ca>
	<19073.9732.319993.862295@lynne.math.ethz.ch>
	<20090811100201.GA19381@cs.cas.cz>
	<20090812115046.GA17118@cs.cas.cz>
	<19074.52084.426535.783434@lynne.math.ethz.ch>
Message-ID: <20090812162013.GA13341@cs.cas.cz>

On Wed, Aug 12, 2009 at 04:02:28PM +0200, Martin Maechler wrote:
> >>>>> "PS" == Petr Savicky <savicky at cs.cas.cz>
> >>>>>     on Wed, 12 Aug 2009 13:50:46 +0200 writes:
> 
>     PS> Let me add the following to the discussion of identical(0, -0).
>     PS> I would like to suggest to replace the paragraph
> 
>     PS> 'identical' sees 'NaN' as different from 'NA_real_', but all
>     PS> 'NaN's are equal (and all 'NA' of the same type are equal).
> 
>     PS> in ?identical by the following text, which is a correction of my previous
>     PS> suggestion for the same paragraph
> 
>     > Components of numerical objects are compared as follows. For non-missing
>     > values, "==" is used. In particular, '0' and '-0' are considered equal. 
>     > All 'NA's of the same type are equal and all 'NaN's are equal, although 
>     > their bit patterns may differ in some cases. 'NA' and 'NaN' are always 
>     > different. 
>     > Note also that 1/0 and 1/(-0) are different.
> 
> the 'numerical' would have to be qualified ('double', 'complex'
> via double), as indeed,  memcmp() is used on integers
> 
> The last sentence is not necessary and probably even confusing:
> Of course, -Inf and Inf are different.

I agree.

>     PS> The suggestion for the default of identical(0, -0) is TRUE, because the
>     PS> negative zero is much less important than NA na NaN and, possibly,
>     PS> distinguishing 0 and -0 could even be deprecated.
> 
> What should that mean??  R *is* using the international floating
> point standards, and 0 and -0 exist there and they *are*
> different!

I am sorry for being too short. In my opinion, distinguishing 0 and -0 is
not useful enough to make the default behavior of identical() different
from the behavior of == in this case.

> If  R  would start --- with a performance penalty, btw ! ---
> to explicitly map all internal '-0' into '+0'  we would
> explicitly move away from the international FP standards... 
> no way!

Yes, i agree. I did not meant this.

>     PS> Moreover, the argument
>     PS> of efficiency of memcmp cannot be used here, since there are different
>     PS> variants of NaN and NA, which should not be distinguished by default.
> 
> your argument is only partly true... as memcmp() can still be
> used instead of '=='  *after* the NA-treatments  {my current
> patch does so},

OK. In this case, memcmp() could still be faster than ==, although 
this is beyond my knowledge.

> and even more as I have been proposing an option "strict"  which
> would only use memcmp()  {and hence also distinguish different
> NA, NaN's}.

I understand the previous messages in this thread as that there is an
agreement that such an option would be very useful and would lead
to faster comparison.

Petr.



[Rd] identical(0, -0)
Petr Savicky