[Issue 5323] std.math: struct FloatingPointControl, duplicate code and assumes X86

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Fri Mar 3 04:05:22 PST 2017


https://issues.dlang.org/show_bug.cgi?id=5323

Guillaume Chatelet <chatelet.guillaume at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |chatelet.guillaume at gmail.co
                   |                            |m

--- Comment #5 from Guillaume Chatelet <chatelet.guillaume at gmail.com> ---
It seems to me that setting rounding mode and testing for inexact does not work
correctly on x86_64.

Correct code using the C bindings:
void main() {
    import core.stdc.fenv;
    fesetround(FE_UPWARD);
    float x = 1.0f;
    x += float.min_normal;
    writefln("%.32g, inexact: %s", x, fetestexcept(FE_INEXACT) > 0);
}

> Output: 1.00000011920928955078125, inexact: true

The same code using FloatingPointControl and IeeeFlags does not work at all
(neither set round nor test except)
void main() {
    resetIeeeFlags();
    FloatingPointControl fpctrl;
    fpctrl.rounding = FloatingPointControl.roundUp;
    float x = 1.0f;
    x += float.min_normal;
    writefln("%.32g, inexact: %s", x, ieeeFlags.inexact);
}

> Output: 1, inexact: false

Linked discussion:
http://forum.dlang.org/post/qybweycrifqgtcssepgx@forum.dlang.org

--


More information about the Digitalmars-d-bugs mailing list