[Issue 24040] dmd different to ldc and gcc for ldexp(f)

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Jul 8 17:49:41 UTC 2023


https://issues.dlang.org/show_bug.cgi?id=24040

--- Comment #2 from Iain Buclaw <ibuclaw at gdcproject.org> ---
By the way, it has occurred to me that DMD's behaviour is essentially no
different to what I'd expect gdc or ldc would emit when compiling with
`-ffast-math`.

When giving it a try with gdc, I indeed did see this behaviour in both gdc and
g++.

```
$ gdc test.d -o test_d -ffast-math -mfpmath=387 -fno-builtin
$ ./test_d
1
0
$ g++ test.cpp -o test_cpp -ffast-math -mfpmath=387
$ ./test_cpp
1
0
```

As soon as I turn on any optimization levels though, the static "mantissa" is
constant propagated and `0 0` is printed at run-time.

(Your C++ test isn't faithful to the D version, adjusted it as follows)

```
#include <cmath>
#include <iostream>

static uint64_t mantissa = 0x8000000000000001UL;

int main() {
    float p =   __builtin_ldexpf((float)mantissa, -213);
    float q =   ldexpf((float)mantissa, -213);
    std::cout << *((unsigned int*)&p) << std::endl;
    std::cout << *((unsigned int*)&q) << std::endl;
}
```

--


More information about the Digitalmars-d-bugs mailing list