該樓層疑似違規已被系統折疊 隐藏此樓檢視此樓
在dev-c++5.7.1中,程式如下:
#include
int main(void)
{
float a=9876543210123456789.0;
double b=9876543210123456789.0,d;
long double c=9876543210123456789.0;
d=(double)c;
printf("float is %2dB\n",sizeof(float));
printf("double is %2dB\n",sizeof(double));
printf("long double is %2dB\n",sizeof(long double));
printf("float a = %30.10f\n",a);
printf("double b = %30.10lf\n",b);
printf("long double c = %30.10Lf\n",c);
printf("double d = c = %30.10Lf\n",d);
}
運作結果為:
float is 4B
double is 8B
long dlouble is 12B
float a=9876543516404875300.0000000000
double b=9876543210123456500.0000000000
long dlouble c= -0.0000000000
double d = c = 9876543210123456500.0000000000
從結果和其它嘗試可知:
(1)long dlouble 是12位元組的浮點數,存儲的資料正确,但是用printf()函數無法輸出?
(2)嘗試過用%lg、%le等格式均不能正确輸出。
(3)此程式在VC++6.0中運作正常,但是VC++6.0中long dlouble是8位元組長的,實際為double型資料,不能回答本問題。
試問:用printf() 如何輸出12位元組的 long double 類型資料?