/* Test whether a basic cpow 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 input2, double complex lower, double complex expected, double complex upper, int flags) { double complex output = cpow(input1, input2); 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.) cpow(%.4f + i*%.4f, %.4f + i*%.4f).real = %.14a, not %.14a, diff %.14a, ratio %.16g", variant, creal(input1), cimag(input1), creal(input2), cimag(input2), 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.) cpow(%.4f + i*%.4f, %.4f + i*%.4f).imag = %.14a, not %.14a, diff %.14a, ratio %.16g", variant, creal(input1), cimag(input1), creal(input2), cimag(input2), 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(90.01, 13.37), CMPLX(10.1, 4.2), CMPLX(-0x1.a7b744e0ecfacp+58, 0x1.c8904a34987d6p+64), CMPLX(-0x1.a7b744e0ecfabp+58, 0x1.c8904a34987d7p+64), CMPLX(-0x1.a7b744e0ecfaap+58, 0x1.c8904a34987d8p+64), 0); test(2, CMPLX(0.0, 13.37), CMPLX(10.1, 4.2), CMPLX(-0x1.00b0eae435459p+24, 0x1.3349c6c089209p+28), CMPLX(-0x1.00b0eae435458p+24, 0x1.3349c6c08920ap+28), CMPLX(-0x1.00b0eae435457p+24, 0x1.3349c6c08920bp+28), 0); test(3, CMPLX(90.01, 0.0), CMPLX(10.1, 4.2), CMPLX(0x1.7b62d7ef33e7cp+65, 0x1.30708851d3e43p+61), CMPLX(0x1.7b62d7ef33e7dp+65, 0x1.30708851d3e44p+61), CMPLX(0x1.7b62d7ef33e7ep+65, 0x1.30708851d3e45p+61), 0); test(4, CMPLX(0.0, 0.0), CMPLX(10.1, 4.2), CMPLX(-0x0.0000000000001p-1022, -0x0.0000000000001p-1022), CMPLX(0x0.0p+0, -0x0.0p+0), CMPLX(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), 0); test(5, CMPLX(90.01, 13.37), CMPLX(0.0, 4.2), CMPLX(0x1.1257d72c3d5f5p-1, 0x1.a66e90bf93e1ep-5), CMPLX(0x1.1257d72c3d5f6p-1, 0x1.a66e90bf93e1fp-5), CMPLX(0x1.1257d72c3d5f7p-1, 0x1.a66e90bf93e2p-5), 0); test(6, CMPLX(0.0, 13.37), CMPLX(0.0, 4.2), CMPLX(-0x1.2b90ed1ba5cdfp-13, -0x1.6398283065df2p-10), CMPLX(-0x1.2b90ed1ba5cdep-13, -0x1.6398283065df1p-10), CMPLX(-0x1.2b90ed1ba5cddp-13, -0x1.6398283065dfp-10), 0); test(7, CMPLX(90.01, 0.0), CMPLX(0.0, 4.2), CMPLX(0x1.ff5b76c771852p-1, 0x1.9a571b9fe137bp-5), CMPLX(0x1.ff5b76c771853p-1, 0x1.9a571b9fe137cp-5), CMPLX(0x1.ff5b76c771854p-1, 0x1.9a571b9fe137dp-5), 0); test(8, CMPLX(90.01, 13.37), CMPLX(10.1, 0.0), CMPLX(0x1.14066062e61ep+62, 0x1.a6b765f53b4cbp+65), CMPLX(0x1.14066062e61e1p+62, 0x1.a6b765f53b4ccp+65), CMPLX(0x1.14066062e61e2p+62, 0x1.a6b765f53b4cdp+65), 0); test(9, CMPLX(0.0, 13.37), CMPLX(10.1, 0.0), CMPLX(-0x1.b330380f193acp+37, -0x1.13b5504ae9249p+35), CMPLX(-0x1.b330380f193abp+37, -0x1.13b5504ae9248p+35), CMPLX(-0x1.b330380f193aap+37, -0x1.13b5504ae9247p+35), 0); test(10, CMPLX(90.01, 0.0), CMPLX(10.1, 0.0), CMPLX(0x1.7bdcea80e3cf3p+65, -0x0.0000000000001p-1022), CMPLX(0x1.7bdcea80e3cf4p+65, 0x0.0p+0), CMPLX(0x1.7bdcea80e3cf5p+65, 0x0.0000000000001p-1022), 0); test(11, CMPLX(0.0, 0.0), CMPLX(10.1, 0.0), CMPLX(-0x0.0000000000001p-1022, -0x0.0000000000001p-1022), CMPLX(0x0.0p+0, -0x0.0p+0), CMPLX(0x0.0000000000001p-1022, 0x0.0000000000001p-1022), 0); test(12, CMPLX(90.01, 13.37), CMPLX(0.0, 0.0), CMPLX(0x1.fffffffffffffp-1, -0x0.0000000000001p-1022), CMPLX(0x1.0p+0, 0x0.0p+0), CMPLX(0x1.0000000000001p+0, 0x0.0000000000001p-1022), 0); test(13, CMPLX(0.0, 13.37), CMPLX(0.0, 0.0), CMPLX(0x1.fffffffffffffp-1, -0x0.0000000000001p-1022), CMPLX(0x1.0p+0, 0x0.0p+0), CMPLX(0x1.0000000000001p+0, 0x0.0000000000001p-1022), 0); test(14, CMPLX(90.01, 0.0), CMPLX(0.0, 0.0), CMPLX(0x1.fffffffffffffp-1, -0x0.0000000000001p-1022), CMPLX(0x1.0p+0, 0x0.0p+0), CMPLX(0x1.0000000000001p+0, 0x0.0000000000001p-1022), 0); return imprecise; }