Floating point rounding

Guillaume Chatelet via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 2 13:10:04 PST 2017


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"


More information about the Digitalmars-d-learn mailing list