mingw - Conversion specifier of long double in C -
the long double data type can have these conversion specifiers in c: %le,%le,%lf,%lg,%lg (reference).
i wrote small program test :
#include <stdio.h> int main(void) { long double d = 656546.67894l; printf("%.0le\n",d); printf("%.0le\n",d); printf("%.0lf\n",d); printf("%.0lg\n",d); printf("%.0lg\n",d); return 0; }
output:
-0
-4e-153
-0
-4e-153
-4e-153
but none giving desired output, 656547 (as may understand). reason?
the compiler used gcc version 3.4.2 (mingw-special).
from old mingw wiki:
mingw uses microsoft c run-time libraries , implementation of printf not support 'long double' type. work-around, cast 'double' , pass printf instead. example:
printf("value = %g\n", (double) my_long_double_value);
note similar problem exists 'long long' type. use 'i64' (eye sixty-four) length modifier instead of gcc's 'll' (ell ell). example:
printf("value = %i64d\n", my_long_long_value);
edit (6 years later): see comment below keith thompson workaround:
#define __use_mingw_ansi_stdio 1
in source file or change command linegcc -d__use_mingw_ansi_stdio=1
Comments
Post a Comment