Menu

#516 Incorrect sign output from modf

v1.0 (example)
open
nobody
None
5
2016-05-26
2015-11-25
stinos
No

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

Discussion

  • WinPORTS

    WinPORTS - 2016-05-26

    Using GCC 6.1.0, we get:

    x = -0 ; hex = 8000000000000000
    x = -100 ; hex = c059000000000000

     
  • adonais

    adonais - 2016-05-26

    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?

     
    • WinPORTS

      WinPORTS - 2016-05-26

      It is MinGW/GCC.

       
  • Johhny

    Johhny - 2016-05-26

    Where can i downloaded lastest mingw 6.1.0?

     
    • WinPORTS

      WinPORTS - 2016-05-26
       
  • Johhny

    Johhny - 2016-05-26

    but what about x64?

     

Log in to post a comment.