mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [BUG] catanf: overflow when the parameter is valid
@ 2020-02-05  8:33 sysysongyue
  2020-02-05 13:32 ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: sysysongyue @ 2020-02-05  8:33 UTC (permalink / raw)
  To: musl

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



[-- Attachment #2: Type: text/html, Size: 393 bytes --]

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

* Re: [musl] [BUG] catanf: overflow when the parameter is valid
  2020-02-05  8:33 [musl] [BUG] catanf: overflow when the parameter is valid sysysongyue
@ 2020-02-05 13:32 ` Rich Felker
  2020-02-05 14:23   ` Rich Felker
  0 siblings, 1 reply; 3+ messages in thread
From: Rich Felker @ 2020-02-05 13:32 UTC (permalink / raw)
  To: sysysongyue; +Cc: musl

On Wed, Feb 05, 2020 at 04:33:43PM +0800, sysysongyue@gmail.com wrote:
>    Hi!
>    I wrote some testcases for catanf(), and found that catanf(1+0*I) return
>    99999996802856924650656260769173209088+99999996802856924650656260769173209088*I,
>    which should return pi/4 in expected. catanl, catanhf, and catanhl have
>    the same problem. Is this a bug? Any patches existed?
>    Thank you in advance!

Looks like the equivalent of commit
10e4bd3780050e75b72aac5d85c31816419bb17d for catan was not applied to
catanf. It should be an easy fix. I'll look at it.

BTW your mail contained an empty plaintext part and the actual message
was buried in the html version. I was able to dig it out to reply, but
try to send text-only or at least with a matching text part since many
readers probably can't see your email and the archive probably missed
the body.

Rich

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

* Re: [musl] [BUG] catanf: overflow when the parameter is valid
  2020-02-05 13:32 ` Rich Felker
@ 2020-02-05 14:23   ` Rich Felker
  0 siblings, 0 replies; 3+ messages in thread
From: Rich Felker @ 2020-02-05 14:23 UTC (permalink / raw)
  To: sysysongyue; +Cc: musl

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

On Wed, Feb 05, 2020 at 08:32:26AM -0500, Rich Felker wrote:
> On Wed, Feb 05, 2020 at 04:33:43PM +0800, sysysongyue@gmail.com wrote:
> >    Hi!
> >    I wrote some testcases for catanf(), and found that catanf(1+0*I) return
> >    99999996802856924650656260769173209088+99999996802856924650656260769173209088*I,
> >    which should return pi/4 in expected. catanl, catanhf, and catanhl have
> >    the same problem. Is this a bug? Any patches existed?
> >    Thank you in advance!
> 
> Looks like the equivalent of commit
> 10e4bd3780050e75b72aac5d85c31816419bb17d for catan was not applied to
> catanf. It should be an easy fix. I'll look at it.
> 
> BTW your mail contained an empty plaintext part and the actual message
> was buried in the html version. I was able to dig it out to reply, but
> try to send text-only or at least with a matching text part since many
> readers probably can't see your email and the archive probably missed
> the body.

Proposed patch attached. It should be identical to the changes in
10e4bd3780050e75b72aac5d85c31816419bb17d except that it's applied to
catanf and catanl.

Rich

[-- Attachment #2: catanfl.diff --]
[-- Type: text/plain, Size: 1358 bytes --]

diff --git a/src/complex/catanf.c b/src/complex/catanf.c
index e10d9c09..ef3907a5 100644
--- a/src/complex/catanf.c
+++ b/src/complex/catanf.c
@@ -87,29 +87,17 @@ float complex catanf(float complex z)
 	x = crealf(z);
 	y = cimagf(z);
 
-	if ((x == 0.0f) && (y > 1.0f))
-		goto ovrf;
-
 	x2 = x * x;
 	a = 1.0f - x2 - (y * y);
-	if (a == 0.0f)
-		goto ovrf;
 
 	t = 0.5f * atan2f(2.0f * x, a);
 	w = _redupif(t);
 
 	t = y - 1.0f;
 	a = x2 + (t * t);
-	if (a == 0.0f)
-		goto ovrf;
 
 	t = y + 1.0f;
 	a = (x2 + (t * t))/a;
-	w = w + (0.25f * logf (a)) * I;
-	return w;
-
-ovrf:
-	// FIXME
-	w = MAXNUMF + MAXNUMF * I;
+	w = CMPLXF(w, 0.25f * logf(a));
 	return w;
 }
diff --git a/src/complex/catanl.c b/src/complex/catanl.c
index a9fc02db..e62526c0 100644
--- a/src/complex/catanl.c
+++ b/src/complex/catanl.c
@@ -97,30 +97,18 @@ long double complex catanl(long double complex z)
 	x = creall(z);
 	y = cimagl(z);
 
-	if ((x == 0.0L) && (y > 1.0L))
-		goto ovrf;
-
 	x2 = x * x;
 	a = 1.0L - x2 - (y * y);
-	if (a == 0.0L)
-		goto ovrf;
 
 	t = atan2l(2.0L * x, a) * 0.5L;
 	w = redupil(t);
 
 	t = y - 1.0L;
 	a = x2 + (t * t);
-	if (a == 0.0L)
-		goto ovrf;
 
 	t = y + 1.0L;
 	a = (x2 + (t * t)) / a;
-	w = w + (0.25L * logl(a)) * I;
-	return w;
-
-ovrf:
-	// FIXME
-	w = LDBL_MAX + LDBL_MAX * I;
+	w = CMPLXF(w, 0.25L * logl(a));
 	return w;
 }
 #endif

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

end of thread, other threads:[~2020-02-05 14:23 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-02-05  8:33 [musl] [BUG] catanf: overflow when the parameter is valid sysysongyue
2020-02-05 13:32 ` Rich Felker
2020-02-05 14:23   ` Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

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 NNTP newsgroup(s).