/* Test whether a basic casinf invocation works. */ /* This test is generated by misc/genbasic.c. */ #include #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) #define MF_ANYSIGN1 (1 << 2) #define MF_ANYSIGN2 (1 << 3) // Soft fail on rounding errors and report only one. int imprecise; void test(int variant, float complex input1, float complex lower, float complex expected, float complex upper, int flags) { float complex output = casinf(input1); if ( !(flags & MF_UNSPEC1) ) { float real = crealf(output); real = (flags & MF_ANYSIGN1) && real < 0.0 ? -real : real; float lower_real = crealf(lower); float expected_real = crealf(expected); float upper_real = crealf(upper); if ( !(isnan(expected_real) ? isnan(real) : isfinite(expected_real) && expected_real != 0.0 ? isfinite(real) && (real == expected_real || (lower_real < real && real < upper_real)) : real == expected_real) ) { if ( imprecise && isfinite(real) && isfinite(expected_real) ) return; warnx("(%d.) casinf(%.4f + i*%.4f).real = %.6a, not %.6a, diff %.6a, ratio %.8g", variant, crealf(input1), cimagf(input1), real, expected_real, real - expected_real, real / expected_real); if ( !isfinite(real) || !isfinite(expected_real) ) exit(1); imprecise = 1; } float imag = cimagf(output); imag = (flags & MF_ANYSIGN2) && imag < 0.0 ? -imag : imag; float lower_imag = cimagf(lower); float expected_imag = cimagf(expected); float upper_imag = cimagf(upper); if ( !(isnan(expected_imag) ? isnan(imag) : isfinite(expected_imag) && expected_imag != 0.0 ? isfinite(imag) && (imag == expected_imag || (lower_imag < imag && imag < upper_imag)) : imag == expected_imag) ) { if ( imprecise && isfinite(imag) && isfinite(expected_imag) ) return; warnx("(%d.) casinf(%.4f + i*%.4f).imag = %.6a, not %.6a, diff %.6a, ratio %.8g", variant, crealf(input1), cimagf(input1), imag, expected_imag, imag - expected_imag, imag / expected_imag); if ( !isfinite(imag) || !isfinite(expected_imag) ) exit(1); imprecise = 1; } } } int main(void) { test(1, CMPLXF(0.9001, 0.1337), CMPLXF(0x1.0d9648p+0, 0x1.116114p-2), CMPLXF(0x1.0d964ap+0, 0x1.116116p-2), CMPLXF(0x1.0d964cp+0, 0x1.116118p-2), 0); test(2, CMPLXF(-0.1234, 0.1337), CMPLXF(-0x1.f62dcap-4, 0x1.130f8ep-3), CMPLXF(-0x1.f62dc8p-4, 0x1.130f9p-3), CMPLXF(-0x1.f62dc6p-4, 0x1.130f92p-3), 0); test(3, CMPLXF(nanf(""), 0.1337), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), 0); test(4, CMPLXF(strtof("inf", NULL), 0.1337), CMPLXF(0x1.921fb4p+0, strtof("inf", NULL)), CMPLXF(0x1.921fb6p+0, strtof("inf", NULL)), CMPLXF(0x1.921fb8p+0, strtof("inf", NULL)), 0); test(5, CMPLXF(strtof("-inf", NULL), 0.1337), CMPLXF(-0x1.921fb8p+0, strtof("inf", NULL)), CMPLXF(-0x1.921fb6p+0, strtof("inf", NULL)), CMPLXF(-0x1.921fb4p+0, strtof("inf", NULL)), 0); test(6, CMPLXF(0.0, 0.1337), CMPLXF(-0x1.0p-149, 0x1.11021ep-3), CMPLXF(0x0.0p+0, 0x1.11022p-3), CMPLXF(0x1.0p-149, 0x1.110222p-3), 0); test(7, CMPLXF(0.9001, -0.1234), CMPLXF(0x1.0f85eep+0, -0x1.0017a2p-2), CMPLXF(0x1.0f85fp+0, -0x1.0017ap-2), CMPLXF(0x1.0f85f2p+0, -0x1.00179ep-2), 0); test(8, CMPLXF(-0.1234, -0.1234), CMPLXF(-0x1.f6d8acp-4, -0x1.fbf9eap-4), CMPLXF(-0x1.f6d8aap-4, -0x1.fbf9e8p-4), CMPLXF(-0x1.f6d8a8p-4, -0x1.fbf9e6p-4), 0); test(9, CMPLXF(nanf(""), -0.1234), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), 0); test(10, CMPLXF(strtof("inf", NULL), -0.1234), CMPLXF(0x1.921fb4p+0, strtof("-inf", NULL)), CMPLXF(0x1.921fb6p+0, strtof("-inf", NULL)), CMPLXF(0x1.921fb8p+0, strtof("-inf", NULL)), 0); test(11, CMPLXF(strtof("-inf", NULL), -0.1234), CMPLXF(-0x1.921fb8p+0, strtof("-inf", NULL)), CMPLXF(-0x1.921fb6p+0, strtof("-inf", NULL)), CMPLXF(-0x1.921fb4p+0, strtof("-inf", NULL)), 0); test(12, CMPLXF(0.0, -0.1234), CMPLXF(-0x1.0p-149, -0x1.f82c2p-4), CMPLXF(0x0.0p+0, -0x1.f82c1ep-4), CMPLXF(0x1.0p-149, -0x1.f82c1cp-4), 0); test(13, CMPLXF(0.9001, nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), 0); test(14, CMPLXF(-0.1234, nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), 0); test(15, CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), 0); test(16, CMPLXF(strtof("inf", NULL), nanf("")), CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), 0 | MF_ANYSIGN2); test(17, CMPLXF(strtof("-inf", NULL), nanf("")), CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), 0 | MF_ANYSIGN2); test(18, CMPLXF(0.0, nanf("")), CMPLXF(-0x1.0p-149, nanf("")), CMPLXF(0x0.0p+0, nanf("")), CMPLXF(0x1.0p-149, nanf("")), 0 | MF_ANYSIGN2); test(19, CMPLXF(0.9001, strtof("inf", NULL)), CMPLXF(-0x1.0p-149, strtof("inf", NULL)), CMPLXF(0x0.0p+0, strtof("inf", NULL)), CMPLXF(0x1.0p-149, strtof("inf", NULL)), 0); test(20, CMPLXF(-0.1234, strtof("inf", NULL)), CMPLXF(-0x1.0p-149, strtof("inf", NULL)), CMPLXF(-0x0.0p+0, strtof("inf", NULL)), CMPLXF(0x1.0p-149, strtof("inf", NULL)), 0); test(21, CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), CMPLXF(nanf(""), strtof("inf", NULL)), 0); test(22, CMPLXF(strtof("inf", NULL), strtof("inf", NULL)), CMPLXF(0x1.921fb4p-1, strtof("inf", NULL)), CMPLXF(0x1.921fb6p-1, strtof("inf", NULL)), CMPLXF(0x1.921fb8p-1, strtof("inf", NULL)), 0); test(23, CMPLXF(strtof("-inf", NULL), strtof("inf", NULL)), CMPLXF(-0x1.921fb8p-1, strtof("inf", NULL)), CMPLXF(-0x1.921fb6p-1, strtof("inf", NULL)), CMPLXF(-0x1.921fb4p-1, strtof("inf", NULL)), 0); test(24, CMPLXF(0.0, strtof("inf", NULL)), CMPLXF(-0x1.0p-149, strtof("inf", NULL)), CMPLXF(0x0.0p+0, strtof("inf", NULL)), CMPLXF(0x1.0p-149, strtof("inf", NULL)), 0); test(25, CMPLXF(0.9001, strtof("-inf", NULL)), CMPLXF(-0x1.0p-149, strtof("-inf", NULL)), CMPLXF(0x0.0p+0, strtof("-inf", NULL)), CMPLXF(0x1.0p-149, strtof("-inf", NULL)), 0); test(26, CMPLXF(-0.1234, strtof("-inf", NULL)), CMPLXF(-0x1.0p-149, strtof("-inf", NULL)), CMPLXF(-0x0.0p+0, strtof("-inf", NULL)), CMPLXF(0x1.0p-149, strtof("-inf", NULL)), 0); test(27, CMPLXF(nanf(""), strtof("-inf", NULL)), CMPLXF(nanf(""), strtof("-inf", NULL)), CMPLXF(nanf(""), strtof("-inf", NULL)), CMPLXF(nanf(""), strtof("-inf", NULL)), 0); test(28, CMPLXF(strtof("inf", NULL), strtof("-inf", NULL)), CMPLXF(0x1.921fb4p-1, strtof("-inf", NULL)), CMPLXF(0x1.921fb6p-1, strtof("-inf", NULL)), CMPLXF(0x1.921fb8p-1, strtof("-inf", NULL)), 0); test(29, CMPLXF(strtof("-inf", NULL), strtof("-inf", NULL)), CMPLXF(-0x1.921fb8p-1, strtof("-inf", NULL)), CMPLXF(-0x1.921fb6p-1, strtof("-inf", NULL)), CMPLXF(-0x1.921fb4p-1, strtof("-inf", NULL)), 0); test(30, CMPLXF(0.0, strtof("-inf", NULL)), CMPLXF(-0x1.0p-149, strtof("-inf", NULL)), CMPLXF(0x0.0p+0, strtof("-inf", NULL)), CMPLXF(0x1.0p-149, strtof("-inf", NULL)), 0); test(31, CMPLXF(0.9001, 0.0), CMPLXF(0x1.1eb83ep+0, -0x1.0p-149), CMPLXF(0x1.1eb84p+0, 0x0.0p+0), CMPLXF(0x1.1eb842p+0, 0x1.0p-149), 0); test(32, CMPLXF(-0.1234, 0.0), CMPLXF(-0x1.fabcf4p-4, -0x1.0p-149), CMPLXF(-0x1.fabcf2p-4, 0x0.0p+0), CMPLXF(-0x1.fabcfp-4, 0x1.0p-149), 0); test(33, CMPLXF(nanf(""), 0.0), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), CMPLXF(nanf(""), nanf("")), 0); test(34, CMPLXF(strtof("inf", NULL), 0.0), CMPLXF(0x1.921fb4p+0, strtof("inf", NULL)), CMPLXF(0x1.921fb6p+0, strtof("inf", NULL)), CMPLXF(0x1.921fb8p+0, strtof("inf", NULL)), 0); test(35, CMPLXF(strtof("-inf", NULL), 0.0), CMPLXF(-0x1.921fb8p+0, strtof("inf", NULL)), CMPLXF(-0x1.921fb6p+0, strtof("inf", NULL)), CMPLXF(-0x1.921fb4p+0, strtof("inf", NULL)), 0); test(36, CMPLXF(0.0, 0.0), CMPLXF(-0x1.0p-149, -0x1.0p-149), CMPLXF(0x0.0p+0, 0x0.0p+0), CMPLXF(0x1.0p-149, 0x1.0p-149), 0); return imprecise; }