- 758 名前:デフォルトの名無しさん [2008/06/06(金) 11:37:44 ]
- #include <stdio.h>
#include <float.h> int main(void) { float f; double x; long double ld; printf("\nTesting the precision of float, double, and long double : \n"); f = 1.0f + 1.0e-7; printf(" 1.0 + 1.0e-7 = %.10f\n", f); f = 1.0f + 1.0e-8; printf(" 1.0 + 1.0e-8 = %.10f\n", f); x = 1.0l + 1.0e-15; printf(" 1.0 + 1.0e-15 = %.20lf\n", x); x = 1.0l + 1.0e-16; printf(" 1.0 + 1.0e-16 = %.20lf\n", x); ld = 1.0L + 1.0e-19; printf(" 1.0 + 1.0e-19 = %.30Lf\n", ld); ld = 1.0L + 1.0e-20; printf(" 1.0 + 1.0e-20 = %.30Lf\n", ld); printf("\nThe experiment above is explained by constants from float.h :\n"); printf(" precision of float : %e\n", FLT_EPSILON); printf(" precision of double : %.15le\n", DBL_EPSILON); printf(" precision of long double : %.30Le\n", LDBL_EPSILON); return 0; } 表示された結果のうち、 1.0 + 1.0e-7 が 1.0000001 にならず、同様に 1.0 + 1.0e-15 が 1.000000000000001 にならず、 1.0 + 1.0e-19 が 1.0000000000000000001 という、きれいな数にならない理由を、FLT_EPSILON, DBL_EPSILON, LDBL_EPSILON との関係から説明してもらえないでしょうか。 よろしくお願いします。
|

|