Fun with floating point
Kenny via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Feb 7 08:06:12 PST 2015
Hi, D community!
I have this program:
import std.stdio;
import std.conv;
int main(string[] argv)
{
float eps = 1.0f;
float f = 0.0f;
while (f + eps != f)
f += 1.0f;
writeln("eps = " ~ to!string(eps) ~ ", max_f = " ~
to!string(f));
return 0;
}
According to the languge specification what result would you
expect from its execution?
When running similar C++ program (VS 2013) the loop terminates
and I get t = 2^24 = 16777216.
Does D language specifies that loop will be terminated for this
program or ?
I compiled with DMD and it hungs.
Details about assembly generated by DMD can be found here:
http://stackoverflow.com/questions/28380651/floating-point-maxing-out-loop-doesnt-terminate-in-d-works-in-c
Thanks.
More information about the Digitalmars-d-learn
mailing list