Skip to content

Instantly share code, notes, and snippets.

@gut
Created May 28, 2015 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gut/6c570934e24afb72df1c to your computer and use it in GitHub Desktop.
Save gut/6c570934e24afb72df1c to your computer and use it in GitHub Desktop.
modf different behavior on gcc 4.9.0-6 VS at 8.0 on a POWER8 machine
[root@ 64b 13:44:10 /tmp/modf]$ uname -m
ppc64le
[root@ 64b 13:44:17 /tmp/modf]$ cat /proc/cpuinfo
processor : 0
cpu : POWER8E (raw), altivec supported
clock : 3425.000000MHz
revision : 2.1 (pvr 004b 0201)
timebase : 512000000
platform : pSeries
model : IBM pSeries (emulated by qemu)
machine : CHRP IBM pSeries (emulated by qemu)
[root@ 64b 13:44:19 /tmp/modf]$ /opt/at8.0/bin/gcc --version
gcc (GCC) 4.9.2 20141013 (Advance-Toolchain-at8.0) [ibm/gcc-4_9-branch, revision: 216164 merged from gcc-4_9-branch, revision 216151]
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@ 64b 13:44:27 /tmp/modf]$ gcc --version
gcc (Debian 4.9.0-6) 4.9.0
Copyright (C) 2014 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
[root@ 64b 13:44:31 /tmp/modf]$ cat modf.c
#include<stdio.h>
#include<math.h>
int main ()
{
double x, fractpart, intpart;
x = 8.123456;
fractpart = modf(x, &intpart);
printf("%16lf : Integral part = %16lf\tFraction Part = %16lf\n", x, intpart, fractpart);
x = -8.123456;
fractpart = modf(x, &intpart);
printf("%16lf : Integral part = %16lf\tFraction Part = %16lf\n", x, intpart, fractpart);
x = 8;
fractpart = modf(x, &intpart);
printf("%16lf : Integral part = %16lf\tFraction Part = %16lf\n", x, intpart, fractpart);
x = -8;
fractpart = modf(x, &intpart);
printf("%16lf : Integral part = %16lf\tFraction Part = %16lf\n", x, intpart, fractpart);
return(0);
}
[root@ 64b 13:44:36 /tmp/modf]$ gcc modf.c -o modf.gcc
[root@ 64b 13:44:59 /tmp/modf]$ /opt/at8.0/bin/gcc modf.c -o modf.at
[root@ 64b 13:45:07 /tmp/modf]$ ./modf.gcc
8.123456 : Integral part = 8.000000 Fraction Part = 0.123456
-8.123456 : Integral part = -8.000000 Fraction Part = -0.123456
8.000000 : Integral part = 8.000000 Fraction Part = 0.000000
-8.000000 : Integral part = -8.000000 Fraction Part = 0.000000
[root@ 64b 13:45:12 /tmp/modf]$ ./modf.at
8.123456 : Integral part = 8.000000 Fraction Part = 0.123456
-8.123456 : Integral part = -8.000000 Fraction Part = -0.123456
8.000000 : Integral part = 8.000000 Fraction Part = 0.000000
-8.000000 : Integral part = -8.000000 Fraction Part = -0.000000
## Note the -0.0 on at8.0!! ##
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment