Floating point rounding

Guillaume Chatelet via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Mar 2 12:30:47 PST 2017


I would expect that (1.0f + smallest float subnormal) > 1.0f when 
the Floating Point unit is set to Round Up.

Here is some C++ code:
#include <limits>
#include <cstdio>
#include <cfenv>

int main(int, char**) {
     std::fesetround(FE_UPWARD);
     printf("%.32g\n", std::numeric_limits<float>::denorm_min() + 
1.0f);
     return 0;
}

Execution on my machine yields:
clang++ --std=c++11 test_denormal.cc && ./a.out
1.00000011920928955078125

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?



More information about the Digitalmars-d-learn mailing list