Optimizing with dmd disables floating point exceptions

Jens Mueller jens.k.mueller at gmx.de
Fri Apr 29 00:10:13 PDT 2011


KennyTM~ wrote:
> On Apr 29, 11 14:27, Walter Bright wrote:
> >That's because the a/=1.0L; is a dead assignment and is removed by the
> >optimizer.
> 
> I'd say it's a wrong-code bug.
> 
> -------------------------------------
> import std.math, std.stdio;
> void main() {
>      auto a = 1.0, b = 0.0;
>      writeln(a);
>      writeln(ieeeFlags.divByZero);
>      auto c = a / b;    // <-- this is no longer dead right?
>      writeln(c);
>      writeln(ieeeFlags.divByZero);
> }
> -------------------------------------
> 1
> false
> 9.50035e-306
> false
> -------------------------------------

I think the compiler performs that floating point division at compile
time. I should look at the assembly. So the floating point exception
happens at that point. Shouldn't the compiler tell me this somehow? Ask
differently how do I get to know when my compile time function causes
floating point exceptions?
Interestingly the results are not the same. Shouldn't in both cases
assert(a == real.infinity, to!(string)(a));
hold.
Without optimization it holds. Why does it not hold with optimizations?

Jens


More information about the Digitalmars-d mailing list