/* error7.c 桁落ち現象 2次方程式 ax^2 + x + 1 = 0 の解 */ #include #include main() { int j; float a,b=1.0,c=1.0,x,y,s; printf("\t\t\t 正しい値\t公式どおり\n"); for(j=1;j<=8;j++){ a=pow(10.0,-j); s=sqrt(b*b-4*a*c); x=(-b+s)/(2.0*a); // 公式どおり y=(2.0*c)/(-b-s); // 工夫した式(正しい値) printf("a = 10^(-%d) のとき \t%9.6f\t%9.6f\n",j,y,x); } }