From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12691 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: catan errors Date: Tue, 10 Apr 2018 15:50:07 -0400 Message-ID: <20180410195007.GI3094@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="Nq2Wo0NMKNjxTN9z" X-Trace: blaine.gmane.org 1523389704 29140 195.159.176.226 (10 Apr 2018 19:48:24 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 10 Apr 2018 19:48:24 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12707-gllmg-musl=m.gmane.org@lists.openwall.com Tue Apr 10 21:48:18 2018 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1f5zFV-0007JH-2O for gllmg-musl@m.gmane.org; Tue, 10 Apr 2018 21:48:14 +0200 Original-Received: (qmail 30621 invoked by uid 550); 10 Apr 2018 19:50:20 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 30543 invoked from network); 10 Apr 2018 19:50:19 -0000 Content-Disposition: inline Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12691 Archived-At: --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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 --Nq2Wo0NMKNjxTN9z Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="catan.diff" 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; } --Nq2Wo0NMKNjxTN9z--