我一直在阅读C Primer Plus书并找到了这个例子
#include <stdio.h>
int main(void)
{
float aboat = 32000.0;
double abet = 2.14e9;
long double dip = 5.32e-5;
printf("%f can be written %e\n", aboat, aboat);
printf("%f can be written %e\n", abet, abet);
printf("%f can be written %e\n", dip, dip);
return 0;
}
在我的 macbook 上运行此程序后,我对输出感到非常震惊:
32000.000000 can be written 3.200000e+04
2140000000.000000 can be written 2.140000e+09
2140000000.000000 can be written 2.140000e+09
所以我环顾四周,发现显示 long double 的正确格式是使用%Lf
. 但是我仍然不明白为什么我得到了 doubleabet
值而不是我在Cygwin、Ubuntu和iDeneb上运行它时得到的值,这大致是
-1950228512509697486020297654959439872418023994430148306244153100897726713609
013030397828640261329800797420159101801613476402327600937901161313172717568.0
00000 can be written 2.725000e+02
有任何想法吗?