import std.math, std.stdio;
void main()
{
double x = sqrt(2.0);
writeln(x);
}
prints
-2.7341e-53
Comment #1 by clugdbug — 2009-04-06T14:15:25Z
Confirmed. Crucial information missing: on Windows at least, this is only with -O.
dmd -run bug.d
1.41421
dmd -run -O bug.d
-2.7341e-53
I'm raising this to regression.
Comment #2 by dsimcha — 2009-04-06T14:19:16Z
Yes. Also, this seems to happen only for sqrt(double) not sqrt(float) or sqrt(real).
Comment #3 by clugdbug — 2009-04-07T02:08:12Z
Not so.
float x = sqrt(2.0f);
is also wrong.
It only affects compile-time constants:
double y = 2.0;
double x = sqrt(y);
works correctly.