/* Test whether a basic frexpf invocation works. */ /* This test is generated by misc/genbasic.c. */ #include #include #include #include "../basic.h" #pragma STDC FENV_ACCESS ON #define MF_UNSPEC1 (1 << 0) #define MF_UNSPEC2 (1 << 1) #define MF_MAYERR (1 << 2) // Soft fail on rounding errors and report only one. int imprecise; static const char* fperrname(int excepts) { switch ( excepts ) { case 0: return "FE_NONE"; case FE_INVALID: return "FE_INVALID"; case FE_DIVBYZERO: return "FE_DIVBYZERO"; case FE_OVERFLOW: return "FE_OVERFLOW"; case FE_UNDERFLOW: return "FE_UNDERFLOW"; default: return "FE_MULTIPLE"; } } void test(int variant, float input1, int errnum, int fperr, float lower, float expected, int expected_exp, float upper, int flags) { errno = 0; if ( feclearexcept(FE_ALL_EXCEPT) ) errx(1, "feclearexcept"); int exp; float output = frexpf(input1, &exp); if ( errnum == 0 && errno ) err(1, "(%d.) frexpf(%.4f) failed", variant, input1); if ( (math_errhandling & MATH_ERRNO) && errnum && errno != errnum ) errx(1, "(%d.) frexpf(%.4f) did not %s", variant, input1, strerrno(errnum)); int excepts = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW); if ( fperr == 0 && excepts ) errx(1, "(%d.) frexpf(%.4f) %s", variant, input1, fperrname(excepts)); if ( (math_errhandling & MATH_ERREXCEPT) && fperr != 0 && excepts != fperr && !((flags & MF_MAYERR) && !excepts) ) errx(1, "(%d.) frexpf(%.4f) did not %s", variant, input1, fperrname(fperr)); if ( !(flags & MF_UNSPEC1) ) { if ( !(isnan(expected) ? isnan(output) : isfinite(expected) && expected != 0.0 ? isfinite(output) && (output == expected || (lower < output && output < upper)) : output == expected) ) { if ( imprecise && isfinite(output) && isfinite(expected) ) return; warnx("(%d.) frexpf(%.4f) = %.6a, not %.6a, diff %.6a, ratio %.8g", variant, input1, output, expected, output - expected, output / expected); if ( !isfinite(output) || !isfinite(expected) ) exit(1); imprecise = 1; } } if ( !(flags & MF_UNSPEC2) ) { if ( exp != expected_exp ) errx(1, "(%d.) frexpf(%.4f).exp = %d, not %d", variant, input1, exp, expected_exp); } } int main(void) { test(1, 90.01, 0, 0, 0x1.680a3cp-1, 0x1.680a3ep-1, 7, 0x1.680a4p-1, 0); test(2, -12.34, 0, 0, -0x1.8ae14ap-1, -0x1.8ae148p-1, 4, -0x1.8ae146p-1, 0); test(3, nanf(""), 0, 0, nanf(""), nanf(""), 0, nanf(""), 0 | MF_UNSPEC2); test(4, strtof("inf", NULL), 0, 0, strtof("inf", NULL), strtof("inf", NULL), 0, strtof("inf", NULL), 0 | MF_UNSPEC2); test(5, strtof("-inf", NULL), 0, 0, strtof("-inf", NULL), strtof("-inf", NULL), 0, strtof("-inf", NULL), 0 | MF_UNSPEC2); test(6, 0.0, 0, 0, -0x1.0p-149, 0x0.0p+0, 0, 0x1.0p-149, 0); return imprecise; }