/* Test whether a basic cargf 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 lower, float expected, float upper, int flags) { float output = cargf(input1); 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.) cargf(%.4f + i*%.4f) = %.6a, not %.6a, diff %.6a, ratio %.8g", variant, crealf(input1), cimagf(input1), output, expected, output - expected, output / expected); if ( !isfinite(output) || !isfinite(expected) ) exit(1); imprecise = 1; } } } int main(void) { test(1, CMPLXF(90.01, 13.37), 0x1.2dfffp-3, 0x1.2dfff2p-3, 0x1.2dfff4p-3, 0); test(2, CMPLXF(-12.34, 13.37), 0x1.2877b8p+1, 0x1.2877bap+1, 0x1.2877bcp+1, 0); test(3, CMPLXF(nanf(""), 13.37), nanf(""), nanf(""), nanf(""), 0); test(4, CMPLXF(strtof("inf", NULL), 13.37), -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(5, CMPLXF(strtof("-inf", NULL), 13.37), 0x1.921fb4p+1, 0x1.921fb6p+1, 0x1.921fb8p+1, 0); test(6, CMPLXF(0.0, 13.37), 0x1.921fb4p+0, 0x1.921fb6p+0, 0x1.921fb8p+0, 0); test(7, CMPLXF(90.01, -12.34), -0x1.17086cp-3, -0x1.17086ap-3, -0x1.170868p-3, 0); test(8, CMPLXF(-12.34, -12.34), -0x1.2d97cap+1, -0x1.2d97c8p+1, -0x1.2d97c6p+1, 0); test(9, CMPLXF(nanf(""), -12.34), nanf(""), nanf(""), nanf(""), 0); test(10, CMPLXF(strtof("inf", NULL), -12.34), -0x1.0p-149, -0x0.0p+0, 0x1.0p-149, 0); test(11, CMPLXF(strtof("-inf", NULL), -12.34), -0x1.921fb8p+1, -0x1.921fb6p+1, -0x1.921fb4p+1, 0); test(12, CMPLXF(0.0, -12.34), -0x1.921fb8p+0, -0x1.921fb6p+0, -0x1.921fb4p+0, 0); test(13, CMPLXF(90.01, nanf("")), nanf(""), nanf(""), nanf(""), 0); test(14, CMPLXF(-12.34, nanf("")), nanf(""), nanf(""), nanf(""), 0); test(15, CMPLXF(nanf(""), nanf("")), nanf(""), nanf(""), nanf(""), 0); test(16, CMPLXF(strtof("inf", NULL), nanf("")), nanf(""), nanf(""), nanf(""), 0); test(17, CMPLXF(strtof("-inf", NULL), nanf("")), nanf(""), nanf(""), nanf(""), 0); test(18, CMPLXF(0.0, nanf("")), nanf(""), nanf(""), nanf(""), 0); test(19, CMPLXF(90.01, strtof("inf", NULL)), 0x1.921fb4p+0, 0x1.921fb6p+0, 0x1.921fb8p+0, 0); test(20, CMPLXF(-12.34, strtof("inf", NULL)), 0x1.921fb4p+0, 0x1.921fb6p+0, 0x1.921fb8p+0, 0); test(21, CMPLXF(nanf(""), strtof("inf", NULL)), nanf(""), nanf(""), nanf(""), 0); test(22, CMPLXF(strtof("inf", NULL), strtof("inf", NULL)), 0x1.921fb4p-1, 0x1.921fb6p-1, 0x1.921fb8p-1, 0); test(23, CMPLXF(strtof("-inf", NULL), strtof("inf", NULL)), 0x1.2d97c6p+1, 0x1.2d97c8p+1, 0x1.2d97cap+1, 0); test(24, CMPLXF(0.0, strtof("inf", NULL)), 0x1.921fb4p+0, 0x1.921fb6p+0, 0x1.921fb8p+0, 0); test(25, CMPLXF(90.01, strtof("-inf", NULL)), -0x1.921fb8p+0, -0x1.921fb6p+0, -0x1.921fb4p+0, 0); test(26, CMPLXF(-12.34, strtof("-inf", NULL)), -0x1.921fb8p+0, -0x1.921fb6p+0, -0x1.921fb4p+0, 0); test(27, CMPLXF(nanf(""), strtof("-inf", NULL)), nanf(""), nanf(""), nanf(""), 0); test(28, CMPLXF(strtof("inf", NULL), strtof("-inf", NULL)), -0x1.921fb8p-1, -0x1.921fb6p-1, -0x1.921fb4p-1, 0); test(29, CMPLXF(strtof("-inf", NULL), strtof("-inf", NULL)), -0x1.2d97cap+1, -0x1.2d97c8p+1, -0x1.2d97c6p+1, 0); test(30, CMPLXF(0.0, strtof("-inf", NULL)), -0x1.921fb8p+0, -0x1.921fb6p+0, -0x1.921fb4p+0, 0); test(31, CMPLXF(90.01, 0.0), -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(32, CMPLXF(-12.34, 0.0), 0x1.921fb4p+1, 0x1.921fb6p+1, 0x1.921fb8p+1, 0); test(33, CMPLXF(nanf(""), 0.0), nanf(""), nanf(""), nanf(""), 0); test(34, CMPLXF(strtof("inf", NULL), 0.0), -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); test(35, CMPLXF(strtof("-inf", NULL), 0.0), 0x1.921fb4p+1, 0x1.921fb6p+1, 0x1.921fb8p+1, 0); test(36, CMPLXF(0.0, 0.0), -0x1.0p-149, 0x0.0p+0, 0x1.0p-149, 0); return imprecise; }