Floating point constant folding

Johan Engelen via Digitalmars-d digitalmars-d at puremagic.com
Fri Mar 3 14:35:15 PST 2017


On Friday, 3 March 2017 at 09:31:19 UTC, Guillaume Chatelet wrote:
> 
> Considering the floating point operations have a runtime 
> component, it seems to me that constant folding is not allowed 
> to occur in the first example. For example, it does not occur 
> in the following C++ snippet:
> ---
> #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;
> }

Clang without/with optimizations turned on:
❯ clang++ float.cpp && ./a.out
1.00000011920928955078125

❯ clang++ float.cpp -O3 && ./a.out
1

-Johan



More information about the Digitalmars-d mailing list