考虑这个简单的代码(t0.c):
#include <stdio.h>
#include <float.h>
#if DBL_HAS_SUBNORM == 1
double d = 0x23d804860c09bp-1119;
int main(void)
{
printf("%a\n", d);
return 0;
}
#endif
调用和输出:
# host: CPU: Intel, OS: Windows 10
$ gcc t0.c -std=c11 && ./a.exe
0x1.2p-1070
# host: CPU: Intel, OS: Windows 10
$ clang t0.c -std=c11 && ./a.exe
0x1.2p-1070
# host: CPU: Intel, OS: Linux
$ gcc t0.c -std=c11 && ./a.out
0x0.0000000000012p-1022
# host: CPU: Intel, OS: Linux
$ clang t0.c -std=c11 && ./a.out
0x0.0000000000012p-1022
问题:对于转换说明符%a
,如何:
- 选择了十六进制浮点常量的确切格式,并且
- 这个十六进制浮点常数的参数选择?
例如,为什么0x1.2p-1070
而不是0x0.0000000000012p-1022
(或其他变体)(反之亦然)?