On 03/02/2017 10:10 PM, Guillaume Chatelet wrote:
On Thursday, 2 March 2017 at 20:30:47 UTC, Guillaume Chatelet wrote:
Here is the same code in D:
void main(string[] args)
{
    import std.math;
    FloatingPointControl fpctrl;
    fpctrl.rounding = FloatingPointControl.roundUp;
    writefln("%.32g", float.min_normal + 1.0f);
}

Execution on my machine yields:
dmd -run test_denormal.d
1

Did I miss something?

This example is closer to the C++ one:

void main(string[] args)
{
    import core.stdc.fenv;
    fesetround(FE_UPWARD);
    writefln("%.32g", float.min_normal + 1.0f);
}

It still yields "1"

This prints the same as the C++ version:

----
void main(string[] args)
{
    import std.stdio;
    import core.stdc.fenv;
    fesetround(FE_UPWARD);
    float x = 1.0f;
    x += float.min_normal;
    writefln("%.32g", x);
}
----

Soo, a bug/limitation of constant folding?

With FloatingPointControl it still prints "1". Does FloatingPointControl.rounding do something different than fesetround? The example in the docs [1] only shows how it changes rint's behavior.


[1] http://dlang.org/phobos/std_math.html#.FloatingPointControl

Reply via email to