c - huge printf float/double difference in integer digits on windows/linux -


#include <float.h>  #include <stdio.h>   int main(int argc, char** argv)  {    printf("[0] %f\n", flt_max);    printf("[1] %lf\n", flt_max);    printf("[2] %lf\n", flt_max); // gcc warning: expects argument of type     ‘long double’    printf("[3] %f\n", dbl_max);    printf("[4] %lf\n", dbl_max);    printf("[5] %lf\n", dbl_max); // gcc warning: expects argument of type     ‘long double’     //using c++ und std::numeric_limits<float/double>::max() gives same     results    return 0;  }  

linux: x64 lsb_release -d prints "description: ubuntu 15.04" gcc --version prints "gcc (ubuntu 4.9.2-10ubuntu13) 4.9.2" ldd --version prints "ldd (ubuntu glibc 2.21-0ubuntu4) 2.21"

[0] 340282346638528859811704183484516925440.000000  [1] 340282346638528859811704183484516925440.000000  [2] --> warning-line disabled  [3] 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000  [4] 179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368.000000  [5] --> warning-line disabled 

windows 7 x64: vs2010 (latest version 10.0.40219.1 sp1rel) debug/win32

[0] 340282346638528860000000000000000000000.000000  [1] 340282346638528860000000000000000000000.000000  [2] 340282346638528860000000000000000000000.000000 [3] 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000  [4] 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000  [5] 179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000     

difference on flt_max vs2010: 340282346638528860000000000000000000000.000000 gcc4.9.2: 340282346638528859811704183484516925440.000000

is 1.8829581651548307456e+20 (not small) - , getting bigger using doubles

update: actual question

is there way (with small change of code) same result on linux , windows (and others) or need use same implementation on systems? i'm afraid of having own implementation windows/linux/linux-arm/vxworks/solaris platforms.

the printf function implemented differently on these platforms.

look @ code:

#include <stdio.h>  int main() {     printf("%lf\n", ((double)1e100)/3);     return 0; } 

this program compiled vc++ gives:

3333333333333333200000000000000000000000000000000000000000000000000000000000000000000000000000000000.000000 

while same program compiled g++ gives:

3333333333333333224453896013722304246165110619355184909726539264904319486405759542029132894851563520.000000 

Comments

Popular posts from this blog

How to connect android app to App engine -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

php - display validation error message next to the textbox in codeigniter -