From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 2659A383F422; Mon, 17 May 2021 02:17:03 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 2659A383F422 From: "sebastian-glibc at sipsolutions dot net" To: glibc-bugs@sourceware.org Subject: [Bug math/27875] New: Complex power `0^1` gives good result but sets division error flag Date: Mon, 17 May 2021 02:17:02 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: math X-Bugzilla-Version: 2.31 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sebastian-glibc at sipsolutions dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 17 May 2021 02:17:03 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D27875 Bug ID: 27875 Summary: Complex power `0^1` gives good result but sets division error flag Product: glibc Version: 2.31 Status: UNCONFIRMED Severity: normal Priority: P2 Component: math Assignee: unassigned at sourceware dot org Reporter: sebastian-glibc at sipsolutions dot net Target Milestone: --- We had a request in NumPy to return a non NaN value for `0j^(1 + Xj)`.=20 Exploring that, I think that glibc gives perfectly good values, including t= he correct sign of the 0. However, the divide by zero floating error flag is set. Since the return v= alue is finite, I would not expect it to get set? This is the result of a test code run (note the first two examples): ``` Calculating for (0 + 0j)^(1 + 1j): Result is: 0+-0j Divide by zero flag set. Calculating for (0 + 0j)^(1 + -1j): Result is: 0+0j Divide by zero flag set. Calculating for (0 + 0j)^(-1 + 1j): Result is: inf+-nanj Divide by zero flag set. Invalid flag set. Calculating for (0 + 0j)^(-1 + -1j): Result is: inf+-nanj Divide by zero flag set. Invalid flag set. ``` Generated with the following program: ``` #include #include #include static void print_cpow(complex mantissa, complex exponent) { printf("\nCalculating for (%g + %gj)^(%g + %gj):\n", creal(mantissa), cimag(mantissa), creal(exponent), cimag(exponent= )); fetestexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID); complex res =3D cpow(mantissa, exponent); int except =3D fetestexcept(FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW | FE_INVALID); printf(" Result is: %g+%gj\n", creal(res), cimag(res)); if (except & FE_DIVBYZERO) { printf(" Divide by zero flag set.\n"); } if (except & FE_OVERFLOW) { printf(" Overflow flag set.\n"); } if (except & FE_UNDERFLOW) { printf(" Underflow flag set.\n"); } if (except & FE_INVALID) { printf(" Invalid flag set.\n"); } } int main(void) { complex exponents[] =3D {1.0+1.0*I, 1.0-1.0*I, -1.0+1.0*I, -1.0-1.0*I}; for(int i =3D 0; i < 4; i++){ print_cpow(-0, exponents[i]); } return 0; } ``` And for completeness: * gcc (Debian 10.2.1-6) 10.2.1 20210110 * ldd (Debian GLIBC 2.31-11) 2.31 * Compiled without any optimization flags: gcc cexp.c -lm --=20 You are receiving this mail because: You are on the CC list for the bug.=