/* Test whether a basic catanh 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 = catanh(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.) catanh(%.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.) catanh(%.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.37a56422cf94ep+0, 0x1.ffa9b4cf569c3p-2), CMPLX(0x1.37a56422cf94fp+0, 0x1.ffa9b4cf569c4p-2), CMPLX(0x1.37a56422cf95p+0, 0x1.ffa9b4cf569c5p-2), 0); test(2, CMPLX(-0.1234, 0.1337), CMPLX(-0x1.f2e3d50aacdcp-4, 0x1.144961d8f8291p-3), CMPLX(-0x1.f2e3d50aacdbfp-4, 0x1.144961d8f8292p-3), CMPLX(-0x1.f2e3d50aacdbep-4, 0x1.144961d8f8293p-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, 0x1.921fb54442d17p+0), CMPLX(0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(5, CMPLX(strtod("-inf", NULL), 0.1337), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(-0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(6, CMPLX(0.0, 0.1337), CMPLX(-0x0.0000000000001p-1022, 0x1.10340cbb3f5cap-3), CMPLX(0x0.0p+0, 0x1.10340cbb3f5cbp-3), CMPLX(0x0.0000000000001p-1022, 0x1.10340cbb3f5ccp-3), 0); test(7, CMPLX(0.9001, -0.1234), CMPLX(0x1.3dfe147ae9475p+0, -0x1.e9037a9249f37p-2), CMPLX(0x1.3dfe147ae9476p+0, -0x1.e9037a9249f36p-2), CMPLX(0x1.3dfe147ae9477p+0, -0x1.e9037a9249f35p-2), 0); test(8, CMPLX(-0.1234, -0.1234), CMPLX(-0x1.f4393ca16167ep-4, -0x1.fe7b56b2b3caep-4), CMPLX(-0x1.f4393ca16167dp-4, -0x1.fe7b56b2b3cadp-4), CMPLX(-0x1.f4393ca16167cp-4, -0x1.fe7b56b2b3cacp-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, -0x1.921fb54442d19p+0), CMPLX(0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(11, CMPLX(strtod("-inf", NULL), -0.1234), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(-0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(12, CMPLX(0.0, -0.1234), CMPLX(-0x0.0000000000001p-1022, -0x1.f6e76da2ef2dcp-4), CMPLX(0x0.0p+0, -0x1.f6e76da2ef2dbp-4), CMPLX(0x0.0000000000001p-1022, -0x1.f6e76da2ef2dap-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(-0x0.0000000000001p-1022, nan("")), CMPLX(0x0.0p+0, nan("")), CMPLX(0x0.0000000000001p-1022, nan("")), 0); test(17, CMPLX(strtod("-inf", NULL), nan("")), CMPLX(-0x0.0000000000001p-1022, nan("")), CMPLX(-0x0.0p+0, nan("")), CMPLX(0x0.0000000000001p-1022, nan("")), 0); test(18, CMPLX(0.0, nan("")), CMPLX(-0x0.0000000000001p-1022, nan("")), CMPLX(0x0.0p+0, nan("")), CMPLX(0x0.0000000000001p-1022, nan("")), 0); test(19, CMPLX(0.9001, strtod("inf", NULL)), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(20, CMPLX(-0.1234, strtod("inf", NULL)), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(-0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(21, CMPLX(nan(""), strtod("inf", NULL)), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(22, CMPLX(strtod("inf", NULL), strtod("inf", NULL)), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(23, CMPLX(strtod("-inf", NULL), strtod("inf", NULL)), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(-0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(24, CMPLX(0.0, strtod("inf", NULL)), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(25, CMPLX(0.9001, strtod("-inf", NULL)), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(26, CMPLX(-0.1234, strtod("-inf", NULL)), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(-0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(27, CMPLX(nan(""), strtod("-inf", NULL)), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(28, CMPLX(strtod("inf", NULL), strtod("-inf", NULL)), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(29, CMPLX(strtod("-inf", NULL), strtod("-inf", NULL)), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(-0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(30, CMPLX(0.0, strtod("-inf", NULL)), CMPLX(-0x0.0000000000001p-1022, -0x1.921fb54442d19p+0), CMPLX(0x0.0p+0, -0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, -0x1.921fb54442d17p+0), 0); test(31, CMPLX(0.9001, 0.0), CMPLX(0x1.7905e2ace17ecp+0, -0x0.0000000000001p-1022), CMPLX(0x1.7905e2ace17edp+0, 0x0.0p+0), CMPLX(0x1.7905e2ace17eep+0, 0x0.0000000000001p-1022), 0); test(32, CMPLX(-0.1234, 0.0), CMPLX(-0x1.fc0921af779c8p-4, -0x0.0000000000001p-1022), CMPLX(-0x1.fc0921af779c7p-4, 0x0.0p+0), CMPLX(-0x1.fc0921af779c6p-4, 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, 0x1.921fb54442d17p+0), CMPLX(0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(35, CMPLX(strtod("-inf", NULL), 0.0), CMPLX(-0x0.0000000000001p-1022, 0x1.921fb54442d17p+0), CMPLX(-0x0.0p+0, 0x1.921fb54442d18p+0), CMPLX(0x0.0000000000001p-1022, 0x1.921fb54442d19p+0), 0); test(36, CMPLX(0.0, 0.0), CMPLX(-0x0.0000000000001p-1022, -0x0.0000000000001p-1022), CMPLX(0x0.0p+0, 0x0.0p+0), CMPLX(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), 0); return imprecise; }