=================================================================== RCS file: /cvs/djgpp/djgpp/tests/libc/c99/stdlib/t-strtof.c,v retrieving revision 1.1 retrieving revision 1.2 diff -p -u -r1.1 -r1.2 --- djgpp/tests/libc/c99/stdlib/t-strtof.c 2003/01/08 20:18:48 1.1 +++ /cvs/djgpp/djgpp/tests/libc/c99/stdlib/t-strtof.c 2003/01/23 19:53:57 1.2 @@ -1,3 +1,5 @@ +#include +#include #include #include #include @@ -25,6 +27,30 @@ static const float_t tests2[] = { static const size_t n_tests2 = sizeof(tests2) / sizeof(tests2[0]); +typedef struct { + const long double *ld; + const int sign; + const char *str; + const int overflow; +} test3_t; + +static long double ld_float_max; +static long double ld_float_max_10; +static long double ld_double_max; + +static const test3_t tests3[] = { + { &ld_float_max, 1, "FLT_MAX", 0 }, + { &ld_float_max, -1, "-FLT_MAX", 0 }, + { &ld_float_max_10, 1, "FLT_MAX * 10", 1 }, + { &ld_float_max_10, -1, "-FLT_MAX * 10", 1 }, + { &ld_double_max, 1, "DBL_MAX", 1 }, + { &ld_double_max, -1, "-DBL_MAX", 1 }, + { &__dj_long_double_max, 1, "LDBL_MAX", 1 }, + { &__dj_long_double_max, -1, "-LDBL_MAX", 1 } +}; + +static const size_t n_tests3 = sizeof(tests3) / sizeof(tests3[0]); + static void inline result (const size_t n, const float f_in, const float f_out) { @@ -36,8 +62,13 @@ main (void) { char buf[128]; float f_res; + int eq; size_t i; + ld_float_max = __dj_float_max; + ld_float_max_10 = ld_float_max * 10; + ld_double_max = __dj_double_max; + puts("float tests:"); for (i = 0; i < n_tests; i++) { sprintf(buf, "%g", tests[i]); @@ -52,5 +83,29 @@ main (void) result(i + 1, *(const float *) &tests2[i], f_res); } + puts("HUGE_VALF tests:"); + for (i = 0; i < n_tests3; i++) { + sprintf(buf, "%Lg", *(tests3[i].ld) * tests3[i].sign); + f_res = strtof(buf, NULL); + + printf("strtof(sprintf(..., %s)) == %sHUGE_VALF: ", + tests3[i].str, + (tests3[i].sign < 0) ? "-" : ""); + + eq = (f_res == (HUGE_VALF * ((tests3[i].sign < 0) ? -1 : 1))); + + if (tests3[i].overflow) { + if (eq) + puts("Yes - OK"); + else + puts("No - FAIL"); + } else { + if (eq) + puts("Yes - FAIL"); + else + puts("No - OK"); + } + } + return(EXIT_SUCCESS); }