Consider
#include <stdio.h> #include <string.h> #include <math.h> void printdbl( double x ) { long long unsigned hexValue; memcpy( &hexValue, &x, sizeof( hexValue ) ); printf( "x = %.5g ; hex = %016llx \n", x, hexValue ); } void showmodf( double x ) { double y; x = modf( x, &y ); printdbl( x ); printdbl( y ); } int main() { showmodf( -100.0 ); return 0; }
The output is
x = 0 ; hex = 0000000000000000 x = -100 ; hex = c059000000000000
The expected output would be a negative 0, i.e.
x = -0 ; hex = 8000000000000000 x = -100 ; hex = c059000000000000
Using GCC 6.1.0, we get:
x = -0 ; hex = 8000000000000000
x = -100 ; hex = c059000000000000
i have compiled and run the above source code using mingw (gcc 6.1.0) and got the following:
x = 0 ; hex = 0000000000000000
x = -100 ; hex = c059000000000000
mingw-w64: git trunk 7de626
gcc: gcc6-branch 20160526
@MateAR.eu
do you use gnu/gcc or mingw/gcc?
It is MinGW/GCC.
Where can i downloaded lastest mingw 6.1.0?
From here: https://sourceforge.net/projects/mingwbundle/
but what about x64?