Should this be correct behaviour?

Janice Caron caron800 at googlemail.com
Thu Nov 29 13:07:04 PST 2007


On 11/29/07, Walter Bright <newshound1 at digitalmars.com> wrote:
> >     float[] f = new float[1];
> >     float[] g = f.dup;
> >     assert(f == g); /* Passes */
> >     assert(f[0] == g[0]); /* Fails */
> >
> > My question is, shouldn't the first assert also fail?
> >
> > Put another way, how can two arrays be considered equal, if their
> > elements are not considered equal?
>
> You are comparing two array *references* which point to the same array.
> The two references clearly are the same.

I don't see why. I duped the array.

> (f == g) does not compare the contents of the arrays.

I don't understand that. It must do. Isn't that how == works for arrays?

> > I realise that everything is behaving according to spec. But is it sensible?
>
> Yes:
>
> float a;
> float b = a;
> assert(b == a); // fails
>
> And this is how floating point works.

I meant, is it sensible that (f == g), given that (f[0] == g[0]) is false?



More information about the Digitalmars-d mailing list