Should this be correct behaviour?

Sean Kelly sean at f4.ca
Thu Nov 29 13:29:00 PST 2007


Steven Schveighoffer wrote:
> "BCS" wrote
>> Reply to Walter,
>>
>>> Janice Caron wrote:
>>>
>>>> float[] f = new float[1];
>>>> float[] g = f.dup;
>>>> assert(f == g); /* Passes */
>>>>
>>>> My question is, shouldn't the first assert also fail?
>>>>
>>> You are comparing two array *references* which point to the same
>>> array.
>> That dup should have copied. The references should not be equal.
> 
> 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.


Sean



More information about the Digitalmars-d mailing list