c - How to detect if printf will support %a? -
i need losslessly represent double precision float in string, , using
sprintf(buf, "%la", x);
this works fine on system, when built on mingw under windows, gives warning:
unknown conversion type character 'a' in format
i coded workaround case, have trouble detecting when should use workaround -- tried #if __stdc_version__ >= 199901l
, seems gcc/mingw defines if doesn't support %a
. there macro check?
this doesn't answer question "how detect if printf support %a?" in general case, can modify compiler installation %a
supported.
first of , use mingw-w64. up-to-date fork of mingw. original version of mingw not maintained , not fix bugs such experiencing (preferring blame microsoft or something).
using mingw-w64 4.9.2 in windows 10, following code works me:
#include <stdio.h> int main() { double x = 3.14; printf("%a\n", x); }
producing 0x1.91eb85p+1
correct. still deferring microsoft runtime.
your question mentions %la
, %a
, %la
both same , can used print either float
or double
argument.
if want print long double
, microsoft runtime not support that; gcc , ms use different sizes of long double
. have use mingw-w64's own printf implementation:
#define __use_mingw_ansi_stdio 1 #include <stdio.h> int main() { long double x = 3.14; printf("%la\n", x); }
which outputs 0xc.8f5c28f5c28f8p-2
. same number 0x1.91eb85p+1
more precision , different placement of binary point, correct.
Comments
Post a Comment