Optimizing with dmd disables floating point exceptions

Jens Mueller jens.k.mueller at gmx.de
Thu Apr 28 15:02:56 PDT 2011


Hi,

checking whether a floating point exception occurred is good coding
practice for me.

I discovered a strange behavior using dmd.
divByZero.d:
import std.math;
unittest {
    auto a = 1.0L;
    assert(!ieeeFlags.divByZero);
    a /= 0.0L;
    assert(ieeeFlags.divByZero);
}

$ rdmd --main -unittest divByZero.d
passes, but
$ rdmd -O --main -unittest divByZero.d
makes the second assert fail.

Similar behavior if I enable floating point exceptions
    FloatingPointControl fpctrl;
    fpctrl.enableExceptions(FloatingPointControl.severeExceptions);

Without optimization I get a floating point exception. With
optimization the code passes even though it shouldn't.
In sum neither floating point exceptions nor status flags are working
when optimizations are turned on.
$ dmd | head -1
Digital Mars D Compiler v2.052

Jens


More information about the Digitalmars-d mailing list