/* fp-value.c Simple program to test floating point numbers. Input the number of iterations you want on the command line. */ #include #include #include /* DBL_DIG and LDBL_DIG */ #define INCR 0.4 #define INCR_L 0.4L int main(int argc, char **argv) { double n_d = 0.0; double n_dL = 0.0L; long double n_ld = 0.0; long double n_ldL = 0.0L; unsigned long long i, max; char *dummy; if(argc <= 1) { fprintf(stderr, "Usage: %s \n", argv[0]); exit(1); } max = strtoull(argv[1], &dummy, 10); printf("START\n"); printf("double 0.0 is %.*g\n", DBL_DIG, n_d); printf("double 0.0L is %.*g\n", DBL_DIG, n_dL); printf("long double 0.0 is %.*Lg\n", LDBL_DIG, n_ld); printf("long double 0.0L is %.*Lg\n", LDBL_DIG, n_ldL); for(i = 1; i <= max; i++) { n_d += INCR; n_dL += INCR_L; n_ld += INCR; n_ldL += INCR_L; } printf("MIDDLE\n"); printf("double 0.0 is %.*g\n", DBL_DIG, n_d); printf("double 0.0L is %.*g\n", DBL_DIG, n_dL); printf("long double 0.0 is %.*Lg\n", LDBL_DIG, n_ld); printf("long double 0.0L is %.*Lg\n", LDBL_DIG, n_ldL); for(i = 1; i <= max; i++) { n_d -= INCR; n_dL -= INCR_L; n_ld -= INCR; n_ldL -= INCR_L; } printf("END\n"); printf("double 0.0 is %.*g\n", DBL_DIG, n_d); printf("double 0.0L is %.*g\n", DBL_DIG, n_dL); printf("long double 0.0 is %.*Lg\n", LDBL_DIG, n_ld); printf("long double 0.0L is %.*Lg\n", LDBL_DIG, n_ldL); }