Should this be correct behaviour?
Sean Kelly
sean at f4.ca
Thu Nov 29 16:23:23 PST 2007
Derek Parnell wrote:
> On Thu, 29 Nov 2007 13:29:00 -0800, Sean Kelly wrote:
>
>> Steven Schveighoffer wrote:
>>> my guess is the function to compare arrays of any type does a bit for bit
>>> compare?
>> Nope. It calls _adEq, which in turn calls TypeInfo_Af.equals, which
>> then calls TypeInfo_f.equals for each element. The problem is that
>> TypeInfo_f.equals is implemented to return true if either a and b are
>> equal *or* if a and b are both NaN. I have no idea why it does this.
>
> I don't know which is better either as I can see arguments for both.
>
> (1) If (a[n] != b[n]) is true then (a == b) should be false.
>
> however ...
>
> (2) If .dup is designed to make an exact copy of an array then the
> resulting array should be equal to the original array.
>
> I'm tending to think that I prefer the existing D behaviour because it
> allows easier generic code for templates and just 'feels' right.
For what it's worth, I think the reason for the current behavior is to
allow sane interaction with AAs. If NaNs compared not equal via
TypeInfo comparisons then any NaN used as an AA key would result in an
insertion that was lost forever. With this in mind, I think the current
behavior makes the most sense as well.
Sean
More information about the Digitalmars-d
mailing list