[PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i

Joseph Faulls Joseph.Faulls@imgtec.com
Mon Oct 9 10:47:28 GMT 2023


Ping

From: Joseph Faulls
Sent: Tuesday, September 26, 2023 12:07 PM
To: newlib@sourceware.org
Subject: [PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i

Delete check which ensured atan2 was not called with x=0. This is not
necessary as atan2 is defined for x=0 when y != 0. The check incorrectly
resulted in catan returning nan + inf i for when real part is +/- 1 and
imaginary part is 0.

The check could also have implications when called with imaginary number
x + yi where x^2 + y^2 == 1.0. Although this is unlikely due to floating
point precision.
---
newlib/libm/complex/catan.c | 2 --
1 file changed, 2 deletions(-)

diff --git a/newlib/libm/complex/catan.c b/newlib/libm/complex/catan.c
index 77510ec2f..34d75b849 100644
--- a/newlib/libm/complex/catan.c
+++ b/newlib/libm/complex/catan.c
@@ -105,8 +105,6 @@ catan(double complex z)

        x2 = x * x;
        a = 1.0 - x2 - (y * y);
-       if (a == 0.0)
-               goto ovrf;

        t = 0.5 * atan2(2.0 * x, a);
        w = _redupi(t);
--
2.34.1
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://sourceware.org/pipermail/newlib/attachments/20231009/2c8b0377/attachment.htm>


More information about the Newlib mailing list