[Issue 24040] New: dmd different to ldc and gcc for ldexp(f)
    d-bugmail at puremagic.com 
    d-bugmail at puremagic.com
       
    Fri Jul  7 20:02:51 UTC 2023
    
    
  
https://issues.dlang.org/show_bug.cgi?id=24040
          Issue ID: 24040
           Summary: dmd different to ldc and gcc for ldexp(f)
           Product: D
           Version: D2
          Hardware: x86_64
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P1
         Component: druntime
          Assignee: nobody at puremagic.com
          Reporter: john.loughran.colvin at gmail.com
I am surprised to see the different behaviour from dmd below:
dev at dev:~$ cat testfloat.d
import std.stdio;
static import core.math;
static import core.stdc.math;
static ulong mantissa = 0x8000000000000001UL;
void main() {
    float a =       core.math.ldexp(float(mantissa), -213);
    float b = core.stdc.math.ldexpf(float(mantissa), -213);
    writeln(*cast(uint*)&a);
    writeln(*cast(uint*)&b);
}
dev at dev:~$ dmd -run testfloat.d
1
0
dev at dev:~$ ldmd2 -run testfloat.d
0
0
dev at dev:~$ cat test.cpp
#include <cmath>
#include <iostream>
int main() {
    float p =   ldexp(0x8000000000000001UL, -213);
    float q =   ldexpf(0x8000000000000001UL, -213);
    std::cout << *((unsigned int*)&p) << std::endl;
    std::cout << *((unsigned int*)&q) << std::endl;
}
dev at dev:~$ g++ test.cpp -o test_cpp
dev at dev:~$ ./test_cpp
0
0
--
    
    
More information about the Digitalmars-d-bugs
mailing list