From maechler at stat.math.ethz.ch  Wed Aug 12 16:02:28 2009
From: maechler at stat.math.ethz.ch (Martin Maechler)
Date: Wed, 12 Aug 2009 16:02:28 +0200
Subject: [Rd] identical(0, -0)
In-Reply-To: <20090812115046.GA17118@cs.cas.cz>
References: <mailman.23.1249725606.24224.r-devel@r-project.org>
	<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>
Message-ID: <19074.52084.426535.783434@lynne.math.ethz.ch>

>>>>> "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.


    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!
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!


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

Martin



[Rd] identical(0, -0)
Martin Maechler