double.init is real.nan, is it a bug?
bsd
slackovsky at gmail.com
Wed Aug 14 21:01:21 PDT 2013
Hi all,
I think this is a bug, but if not I'm very confused and would
like some clarification.
When checking double values that could be nan or unassigned I
have to check both double.init and double.nan. But double.init IS
double.nan.
---
void main() {
// passes but I believe it is checked during compile
assert(double.init is double.nan);
double val;
std.stdio.writeln( to!string(val) ); // writes "nan" to
console
assert(val is double.init); // passes
assert(val is double.nan); // << FAILS (unexpectedly for me
anyway)
}
---
Why does assert(val is double.nan) fail? Given:
a) double.init is double.nan
b) val is double.init
c) to!string(val) sees val as a nan
I also found this confusing:
---
void main() {
assert(double.init is double.nan); // passes expected
assert(double.init is float.init); // passes, unexpected
assert(double.init is real.init); // passes, unexpected
assert(double.init is real.nan); // passes, unexpected
assert(double.init is float.nan); // passes, unexpected
}
---
I don't think these should be passing...should they??
I'm on fedora 19, dmd 2.063.2 extracted from the ZIP
Thanks
More information about the Digitalmars-d-learn
mailing list