Issue 17243 - std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64
Summary: std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64
Status: RESOLVED FIXED
Alias: None
Product: D
Classification: Unclassified
Component: phobos (show other issues)
Version: D2
Hardware: x86_64 Linux
: P1 normal
Assignee: ag0aep6g
URL:
Keywords: pull
Depends on:
Blocks:
 
Reported: 2017-03-04 15:22 UTC by ag0aep6g
Modified: 2018-01-05 13:27 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description ag0aep6g 2017-03-04 15:22:52 UTC
Compile with dmd (e.g. 2.073.0) and run:

----
void main()
{
    import std.math;
    FloatingPointControl fpctrl;

    fpctrl.rounding = FloatingPointControl.roundUp;
    float u = 1;
    u += 0.1;

    fpctrl.rounding = FloatingPointControl.roundDown;
    float d = 1;
    d += 0.1;

    assert(u > d); /* fails; should pass */
}
----

Similar tests can be constructed for floating point exception flags and masks.

The problem is that dmd generates SSE additions, but FloatingPointConrol doesn't affect SSE's control/status register MXCSR.

See also issue 5323.
Comment 1 ag0aep6g 2017-03-04 15:32:48 UTC
An attempt at a fix: https://github.com/dlang/phobos/pull/5240
Comment 2 ag0aep6g 2017-03-04 18:43:28 UTC
std.math.ieeeFlags is affected as well.

----
void main()
{
    import std.math;
    float x = 1;
    x /= 0;
    assert(ieeeFlags.divByZero); /* fails; should pass */
}
----
Comment 3 github-bugzilla 2017-03-14 10:50:44 UTC
Commits pushed to stable at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/09679c241f9ab4554e5bdabee998fd319e2eb4ac
fix issue 17243 - std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64

https://github.com/dlang/phobos/commit/83e199977607752df16167c557e2c0f5acb12be5
Merge pull request #5240 from aG0aep6G/FloatingPointControl

fix issue 17243 - std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64
Comment 4 github-bugzilla 2017-03-22 12:05:26 UTC
Commits pushed to master at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/09679c241f9ab4554e5bdabee998fd319e2eb4ac
fix issue 17243 - std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64

https://github.com/dlang/phobos/commit/83e199977607752df16167c557e2c0f5acb12be5
Merge pull request #5240 from aG0aep6G/FloatingPointControl
Comment 5 github-bugzilla 2017-08-07 12:26:24 UTC
Commits pushed to newCTFE at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/09679c241f9ab4554e5bdabee998fd319e2eb4ac
fix issue 17243 - std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64

https://github.com/dlang/phobos/commit/83e199977607752df16167c557e2c0f5acb12be5
Merge pull request #5240 from aG0aep6G/FloatingPointControl
Comment 6 github-bugzilla 2018-01-05 13:27:43 UTC
Commits pushed to dmd-cxx at https://github.com/dlang/phobos

https://github.com/dlang/phobos/commit/09679c241f9ab4554e5bdabee998fd319e2eb4ac
fix issue 17243 - std.math.{FloatingPointControl,ieeeFlags} don't work on x86_64

https://github.com/dlang/phobos/commit/83e199977607752df16167c557e2c0f5acb12be5
Merge pull request #5240 from aG0aep6G/FloatingPointControl