mailing list of musl libc
 help / color / mirror / code / Atom feed
* catan errors
@ 2018-04-10 19:50 Rich Felker
  2018-04-10 20:23 ` dgutson .
  2018-04-10 23:08 ` Szabolcs Nagy
  0 siblings, 2 replies; 10+ messages in thread
From: Rich Felker @ 2018-04-10 19:50 UTC (permalink / raw)
  To: musl

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

The OpenBSD catan implementation we're using has a number of
nonsensical "overflow" (goto ovrf) conditions that aren't errors,
reported by mepholic on irc. I think the attached patch fixes them
without introducing new problems, but I'm not sure if any other
problems remain.

Note that, of the three cases removed:

1. Is not an exceptional case at all, and made no sense to begin with.

2. Is only exceptional if x and a are both zero; atan(2x,0) is
   perfectly well-defined.

3. Is only possible if y==1.0 and x==0.0, which is the only real
   exceptional case for atan: z==I.

I opted to replace the non-obvious (3) with an explicit check for z==I
but this isn't necessary.

As written the patch does not address raising exception flags; that
should be fixed before it's committed but right now I'm just
submitting this for comments.

Prior to the patch, at least the following (utterly dumb -- the first
is a very real input!) cases are broken:

- catan(1.0)
- catan(2*I)
- catan(I)

Rich

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

diff --git a/src/complex/catan.c b/src/complex/catan.c
index 39ce6cf..9c2fccf 100644
--- a/src/complex/catan.c
+++ b/src/complex/catan.c
@@ -91,21 +91,17 @@ double complex catan(double complex z)
 	x = creal(z);
 	y = cimag(z);
 
-	if (x == 0.0 && y > 1.0)
+	if (x == 0.0 && y == 1.0)
 		goto ovrf;
 
 	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);
 
 	t = y - 1.0;
 	a = x2 + (t * t);
-	if (a == 0.0)
-		goto ovrf;
 
 	t = y + 1.0;
 	a = (x2 + t * t)/a;
@@ -113,7 +109,6 @@ double complex catan(double complex z)
 	return w;
 
 ovrf:
-	// FIXME
-	w = MAXNUM + MAXNUM * I;
+	w = CMPLX(0, INFINITY);
 	return w;
 }

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

end of thread, other threads:[~2018-04-11  0:52 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-04-10 19:50 catan errors Rich Felker
2018-04-10 20:23 ` dgutson .
2018-04-10 20:32   ` Rich Felker
2018-04-10 20:41     ` dgutson .
2018-04-10 20:50       ` Rich Felker
2018-04-10 21:27         ` dgutson .
2018-04-10 22:14           ` Rich Felker
2018-04-10 23:08 ` Szabolcs Nagy
2018-04-10 23:23   ` Rich Felker
2018-04-11  0:52     ` Szabolcs Nagy

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