#include #define PRE_LOOP 123 #define PRE_LOOP22 1020 #define PRINT_LOOP 58 // PRE_LOOP22 : used for double int main( ) { float a, b; int i; double x, y; /**Underflow (虧失) 絕對值太小小到幾乎是 0 以致於被電腦當作 0: 整數不會 Underflow, 因為 1 再小就變 0; 實數才會:***/ printf("a, b are float.\n"); a = 1.0, b= 1.0; for(i=1; i<= PRE_LOOP; ++i) { a = a*2; b = b / 2; } printf("a=%.8f, b=%.8f\n", a, b); // %f for(i=1; i<= PRINT_LOOP; ++i) { a = a*2; // 會 overflow b = b / 2; // 會 underflow printf("a=%.8g, b=%.8g\n", a, b); } /// printf("\nx, y are double.\n"); x = y = 1.0; for(i=1; i<= PRE_LOOP22; ++i) { x = x*2; y = y / 2; } printf("x=%.18f, y=%.18f\n", x, y); // %f for(i=1; i<= PRINT_LOOP; ++i) { x = x*2; // 會 overflow y = y / 2; // 會 underflow printf("x=%.18g, y=%.18g\n", x, y); } }