public inbox for newlib@sourceware.org
 help / color / mirror / Atom feed
* [PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i
@ 2023-09-26 11:07 Joseph Faulls
  2023-10-09 10:47 ` Joseph Faulls
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Faulls @ 2023-09-26 11:07 UTC (permalink / raw)
  To: newlib

[-- Attachment #1: Type: text/plain, Size: 889 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i
  2023-09-26 11:07 [PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i Joseph Faulls
@ 2023-10-09 10:47 ` Joseph Faulls
  2023-10-10 19:26   ` Jeff Johnston
  0 siblings, 1 reply; 3+ messages in thread
From: Joseph Faulls @ 2023-10-09 10:47 UTC (permalink / raw)
  To: newlib; +Cc: jjohnstn

[-- Attachment #1: Type: text/plain, Size: 1059 bytes --]

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i
  2023-10-09 10:47 ` Joseph Faulls
@ 2023-10-10 19:26   ` Jeff Johnston
  0 siblings, 0 replies; 3+ messages in thread
From: Jeff Johnston @ 2023-10-10 19:26 UTC (permalink / raw)
  To: Joseph Faulls; +Cc: newlib

[-- Attachment #1: Type: text/plain, Size: 1700 bytes --]

Hi Joseph,

Sorry for the delay.  I did a check and the current NetBSD sources still
have that check in them and that was where
this code was taken from.

However, I created a test case and tried it with glibc and also tested with
newlib versions of catan/catanf minus the checks.  They
match without the check so I pushed the change to all 3 of the catan
functions.

-- Jeff J.

On Mon, Oct 9, 2023 at 6:47 AM Joseph Faulls <Joseph.Faulls@imgtec.com>
wrote:

> 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
>

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-10-10 19:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-26 11:07 [PATCH 1/1] newlib: libm: fix complex atan for +/- 1 + 0i Joseph Faulls
2023-10-09 10:47 ` Joseph Faulls
2023-10-10 19:26   ` Jeff Johnston

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).