/* Test whether a basic cacos 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, double complex input1, double complex lower, double complex expected, double complex upper, int flags) { double complex output = cacos(input1); if ( !(flags & MF_UNSPEC1) ) { double real = creal(output); real = (flags & MF_ANYSIGN1) && real < 0.0 ? -real : real; double lower_real = creal(lower); double expected_real = creal(expected); double upper_real = creal(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.) cacos(%.4f + i*%.4f).real = %.14a, not %.14a, diff %.14a, ratio %.16g", variant, creal(input1), cimag(input1), real, expected_real, real - expected_real, real / expected_real); if ( !isfinite(real) || !isfinite(expected_real) ) exit(1); imprecise = 1; } double imag = cimag(output); imag = (flags & MF_ANYSIGN2) && imag < 0.0 ? -imag : imag; double lower_imag = cimag(lower); double expected_imag = cimag(expected); double upper_imag = cimag(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.) cacos(%.4f + i*%.4f).imag = %.14a, not %.14a, diff %.14a, ratio %.16g", variant, creal(input1), cimag(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, CMPLX(0.9001, 0.1337), CMPLX(0x1.0912d6180661cp-1, -0x1.116115ffdc9bdp-2), CMPLX(0x1.0912d6180661dp-1, -0x1.116115ffdc9bcp-2), CMPLX(0x1.0912d6180661ep-1, -0x1.116115ffdc9bbp-2), 0); test(2, CMPLX(-0.1234, 0.1337), CMPLX(0x1.b18291b62e3afp+0, -0x1.130f90867ec5ep-3), CMPLX(0x1.b18291b62e3bp+0, -0x1.130f90867ec5dp-3), CMPLX(0x1.b18291b62e3b1p+0, -0x1.130f90867ec5cp-3), 0); test(3, CMPLX(nan(""), 0.1337), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), 0); test(4, CMPLX(strtod("inf", NULL), 0.1337), CMPLX(-0x0.0000000000001p-1022, strtod("-inf", NULL)), CMPLX(0x0.0p+0, strtod("-inf", NULL)), CMPLX(0x0.0000000000001p-1022, strtod("-inf", NULL)), 0); test(5, CMPLX(strtod("-inf", NULL), 0.1337), CMPLX(0x1.921fb54442d17p+1, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d18p+1, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d19p+1, strtod("-inf", NULL)), 0); test(6, CMPLX(0.0, 0.1337), CMPLX(0x1.921fb54442d17p+0, -0x1.110220d464c24p-3), CMPLX(0x1.921fb54442d18p+0, -0x1.110220d464c23p-3), CMPLX(0x1.921fb54442d19p+0, -0x1.110220d464c22p-3), 0); test(7, CMPLX(0.9001, -0.1234), CMPLX(0x1.05338a3c5b05bp-1, 0x1.0017a0bb4089dp-2), CMPLX(0x1.05338a3c5b05cp-1, 0x1.0017a0bb4089ep-2), CMPLX(0x1.05338a3c5b05dp-1, 0x1.0017a0bb4089fp-2), 0); test(8, CMPLX(-0.1234, -0.1234), CMPLX(0x1.b18d3fc8d88bcp+0, 0x1.fbf9e768354e4p-4), CMPLX(0x1.b18d3fc8d88bdp+0, 0x1.fbf9e768354e5p-4), CMPLX(0x1.b18d3fc8d88bep+0, 0x1.fbf9e768354e6p-4), 0); test(9, CMPLX(nan(""), -0.1234), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), 0); test(10, CMPLX(strtod("inf", NULL), -0.1234), CMPLX(-0x0.0000000000001p-1022, strtod("inf", NULL)), CMPLX(0x0.0p+0, strtod("inf", NULL)), CMPLX(0x0.0000000000001p-1022, strtod("inf", NULL)), 0); test(11, CMPLX(strtod("-inf", NULL), -0.1234), CMPLX(0x1.921fb54442d17p+1, strtod("inf", NULL)), CMPLX(0x1.921fb54442d18p+1, strtod("inf", NULL)), CMPLX(0x1.921fb54442d19p+1, strtod("inf", NULL)), 0); test(12, CMPLX(0.0, -0.1234), CMPLX(0x1.921fb54442d17p+0, 0x1.f82c1d849f4b8p-4), CMPLX(0x1.921fb54442d18p+0, 0x1.f82c1d849f4b9p-4), CMPLX(0x1.921fb54442d19p+0, 0x1.f82c1d849f4bap-4), 0); test(13, CMPLX(0.9001, nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), 0); test(14, CMPLX(-0.1234, nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), 0); test(15, CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), 0); test(16, CMPLX(strtod("inf", NULL), nan("")), CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), 0 | MF_ANYSIGN2); test(17, CMPLX(strtod("-inf", NULL), nan("")), CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), 0 | MF_ANYSIGN2); test(18, CMPLX(0.0, nan("")), CMPLX(0x1.921fb54442d17p+0, nan("")), CMPLX(0x1.921fb54442d18p+0, nan("")), CMPLX(0x1.921fb54442d19p+0, nan("")), 0); test(19, CMPLX(0.9001, strtod("inf", NULL)), CMPLX(0x1.921fb54442d17p+0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d18p+0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d19p+0, strtod("-inf", NULL)), 0); test(20, CMPLX(-0.1234, strtod("inf", NULL)), CMPLX(0x1.921fb54442d17p+0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d18p+0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d19p+0, strtod("-inf", NULL)), 0); test(21, CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("-inf", NULL)), CMPLX(nan(""), strtod("-inf", NULL)), CMPLX(nan(""), strtod("-inf", NULL)), 0); test(22, CMPLX(strtod("inf", NULL), strtod("inf", NULL)), CMPLX(0x1.921fb54442d17p-1, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d18p-1, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d19p-1, strtod("-inf", NULL)), 0); test(23, CMPLX(strtod("-inf", NULL), strtod("inf", NULL)), CMPLX(0x1.2d97c7f3321d1p+1, strtod("-inf", NULL)), CMPLX(0x1.2d97c7f3321d2p+1, strtod("-inf", NULL)), CMPLX(0x1.2d97c7f3321d3p+1, strtod("-inf", NULL)), 0); test(24, CMPLX(0.0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d17p+0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d18p+0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d19p+0, strtod("-inf", NULL)), 0); test(25, CMPLX(0.9001, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d17p+0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d18p+0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d19p+0, strtod("inf", NULL)), 0); test(26, CMPLX(-0.1234, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d17p+0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d18p+0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d19p+0, strtod("inf", NULL)), 0); test(27, CMPLX(nan(""), strtod("-inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), CMPLX(nan(""), strtod("inf", NULL)), 0); test(28, CMPLX(strtod("inf", NULL), strtod("-inf", NULL)), CMPLX(0x1.921fb54442d17p-1, strtod("inf", NULL)), CMPLX(0x1.921fb54442d18p-1, strtod("inf", NULL)), CMPLX(0x1.921fb54442d19p-1, strtod("inf", NULL)), 0); test(29, CMPLX(strtod("-inf", NULL), strtod("-inf", NULL)), CMPLX(0x1.2d97c7f3321d1p+1, strtod("inf", NULL)), CMPLX(0x1.2d97c7f3321d2p+1, strtod("inf", NULL)), CMPLX(0x1.2d97c7f3321d3p+1, strtod("inf", NULL)), 0); test(30, CMPLX(0.0, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d17p+0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d18p+0, strtod("inf", NULL)), CMPLX(0x1.921fb54442d19p+0, strtod("inf", NULL)), 0); test(31, CMPLX(0.9001, 0.0), CMPLX(0x1.cd9dd17ee3a59p-2, -0x0.0000000000001p-1022), CMPLX(0x1.cd9dd17ee3a5ap-2, -0x0.0p+0), CMPLX(0x1.cd9dd17ee3a5bp-2, 0x0.0000000000001p-1022), 0); test(32, CMPLX(-0.1234, 0.0), CMPLX(0x1.b1cb8458ab084p+0, -0x0.0000000000001p-1022), CMPLX(0x1.b1cb8458ab085p+0, -0x0.0p+0), CMPLX(0x1.b1cb8458ab086p+0, 0x0.0000000000001p-1022), 0); test(33, CMPLX(nan(""), 0.0), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), CMPLX(nan(""), nan("")), 0); test(34, CMPLX(strtod("inf", NULL), 0.0), CMPLX(-0x0.0000000000001p-1022, strtod("-inf", NULL)), CMPLX(0x0.0p+0, strtod("-inf", NULL)), CMPLX(0x0.0000000000001p-1022, strtod("-inf", NULL)), 0); test(35, CMPLX(strtod("-inf", NULL), 0.0), CMPLX(0x1.921fb54442d17p+1, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d18p+1, strtod("-inf", NULL)), CMPLX(0x1.921fb54442d19p+1, strtod("-inf", NULL)), 0); test(36, CMPLX(0.0, 0.0), CMPLX(0x1.921fb54442d17p+0, -0x0.0000000000001p-1022), CMPLX(0x1.921fb54442d18p+0, -0x0.0p+0), CMPLX(0x1.921fb54442d19p+0, 0x0.0000000000001p-1022), 0); return imprecise; }