double.init is nan ..?
Adam D. Ruppe
destructionator at gmail.com
Fri Mar 14 09:41:45 PDT 2014
On Friday, 14 March 2014 at 16:25:59 UTC, Etienne wrote:
> Struct.init is unreliable now in my books. Thanks!
Interestingly:
struct A{
int a;
double b;
}
void main() {
A a;
assert(a is A.init); // passes
assert(a == A.init); // fails
double test;
assert(test is double.nan); // fails
}
I struct == other_struct works basically by checking the equality
operator on each member inside.
So that is like saying assert(a.a == A.init.a && b.a ==B.init.b)
which fails cuz of the nan rule.
Whereas struct is other_struct works by just comparing the memory
bytes, regardless of the types of the contents. If they match, it
is considered a pass, which will always be the case for comparing
against init.
More information about the Digitalmars-d
mailing list