/* Test whether a basic powf 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, float input2, int errnum, int fperr, float lower, float expected, float upper, int flags) { errno = 0; if ( feclearexcept(FE_ALL_EXCEPT) ) errx(1, "feclearexcept"); float output = powf(input1, input2); if ( errnum == 0 && errno ) err(1, "(%d.) powf(%.4f, %.4f) failed", variant, input1, input2); if ( (math_errhandling & MATH_ERRNO) && errnum && errno != errnum ) errx(1, "(%d.) powf(%.4f, %.4f) did not %s", variant, input1, input2, strerrno(errnum)); int excepts = fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW); if ( fperr == 0 && excepts ) errx(1, "(%d.) powf(%.4f, %.4f) %s", variant, input1, input2, fperrname(excepts)); if ( (math_errhandling & MATH_ERREXCEPT) && fperr != 0 && excepts != fperr && !((flags & MF_MAYERR) && !excepts) ) errx(1, "(%d.) powf(%.4f, %.4f) did not %s", variant, input1, input2, 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.) powf(%.4f, %.4f) = %.6a, not %.6a, diff %.6a, ratio %.8g", variant, input1, input2, output, expected, output - expected, output / expected); if ( !isfinite(output) || !isfinite(expected) ) exit(1); imprecise = 1; } } } int main(void) { test(1, 90.01, 13.37, 0, 0, 0x1.bd2cp+86, 0x1.bd2c02p+86, 0x1.bd2c04p+86, 0); test(2, -12.34, 13.37, EDOM, FE_INVALID, nanf(""), nanf(""), nanf(""), 0); test(3, nanf(""), 13.37, 0, 0, nanf(""), nanf(""), nanf(""), 0); test(4, strtof("inf", NULL), 13.37, 0, 0, strtof("inf", NULL), strtof("inf", NULL), strtof("inf", NULL), 0); test(5, 0.0, 13.37, 0, 0, -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(6, 90.01, -12.34, 0, 0, 0x1.d9f006p-81, 0x1.d9f008p-81, 0x1.d9f00ap-81, 0); test(7, -12.34, -12.34, EDOM, FE_INVALID, nanf(""), nanf(""), nanf(""), 0); test(8, nanf(""), -12.34, 0, 0, nanf(""), nanf(""), nanf(""), 0); test(9, strtof("inf", NULL), -12.34, 0, 0, -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(10, 0.0, -12.34, ERANGE, FE_DIVBYZERO, strtof("inf", NULL), strtof("inf", NULL), strtof("inf", NULL), 0); test(11, 90.01, nanf(""), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(12, -12.34, nanf(""), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(13, nanf(""), nanf(""), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(14, strtof("inf", NULL), nanf(""), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(15, strtof("-inf", NULL), nanf(""), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(16, 0.0, nanf(""), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(17, 90.01, strtof("inf", NULL), 0, 0, strtof("inf", NULL), strtof("inf", NULL), strtof("inf", NULL), 0); test(18, nanf(""), strtof("inf", NULL), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(19, strtof("inf", NULL), strtof("inf", NULL), 0, 0, strtof("inf", NULL), strtof("inf", NULL), strtof("inf", NULL), 0); test(20, 0.0, strtof("inf", NULL), 0, 0, -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(21, 90.01, strtof("-inf", NULL), 0, 0, -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(22, nanf(""), strtof("-inf", NULL), 0, 0, nanf(""), nanf(""), nanf(""), 0); test(23, strtof("inf", NULL), strtof("-inf", NULL), 0, 0, -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(24, 0.0, strtof("-inf", NULL), ERANGE, FE_DIVBYZERO, strtof("inf", NULL), strtof("inf", NULL), strtof("inf", NULL), 0 | MF_MAYERR); test(25, 90.01, 0.0, 0, 0, 0x1.fffffep-1, 0x1.0p+0, 0x1.000002p+0, 0); test(26, -12.34, 0.0, 0, 0, 0x1.fffffep-1, 0x1.0p+0, 0x1.000002p+0, 0); test(27, nanf(""), 0.0, 0, 0, 0x1.fffffep-1, 0x1.0p+0, 0x1.000002p+0, 0); test(28, strtof("inf", NULL), 0.0, 0, 0, 0x1.fffffep-1, 0x1.0p+0, 0x1.000002p+0, 0); test(29, strtof("-inf", NULL), 0.0, 0, 0, 0x1.fffffep-1, 0x1.0p+0, 0x1.000002p+0, 0); test(30, 0.0, 0.0, 0, 0, 0x1.fffffep-1, 0x1.0p+0, 0x1.000002p+0, 0); return imprecise; }