From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/12702 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: catan errors Date: Tue, 10 Apr 2018 19:23:28 -0400 Message-ID: <20180410232328.GN3094@brightrain.aerifal.cx> References: <20180410195007.GI3094@brightrain.aerifal.cx> <20180410230849.GK4418@port70.net> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="DKU6Jbt7q3WqK7+M" X-Trace: blaine.gmane.org 1523402507 27105 195.159.176.226 (10 Apr 2018 23:21:47 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 10 Apr 2018 23:21:47 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-12718-gllmg-musl=m.gmane.org@lists.openwall.com Wed Apr 11 01:21:42 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 1f62a5-0006oP-0N for gllmg-musl@m.gmane.org; Wed, 11 Apr 2018 01:21:41 +0200 Original-Received: (qmail 30412 invoked by uid 550); 10 Apr 2018 23:23:43 -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 30392 invoked from network); 10 Apr 2018 23:23:42 -0000 Content-Disposition: inline In-Reply-To: <20180410230849.GK4418@port70.net> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:12702 Archived-At: --DKU6Jbt7q3WqK7+M Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Wed, Apr 11, 2018 at 01:08:50AM +0200, Szabolcs Nagy wrote: > * Rich Felker [2018-04-10 15:50:07 -0400]: > > > > 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. > > > .... > > t = y - 1.0; > > a = x2 + (t * t); > > - if (a == 0.0) > > - goto ovrf; > > why does a==0 imply x==0? OK, at least by my reasoning it's only algebraically true not necessarily as doubles. > if |x| < sqrt(2)*0x1p-538, x2 underflows to 0 in nearest rounding mode. > > to handle this correctly extra work would need to be done, so i think > either way is fine (leaving the goto there or not are both wrong, but > we dont guarantee correct complex functions yet) I'm fine with just moving the check back here. But the special case (maybe not near-special cases with internal over/underflow though) works fine just replacing the *I with CMPLX. See attached. Rich --DKU6Jbt7q3WqK7+M Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="catan2.diff" diff --git a/src/complex/catan.c b/src/complex/catan.c index 39ce6cf..7dc2afe 100644 --- a/src/complex/catan.c +++ b/src/complex/catan.c @@ -91,29 +91,17 @@ double complex catan(double complex z) x = creal(z); y = cimag(z); - 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; - w = w + (0.25 * log(a)) * I; - return w; - -ovrf: - // FIXME - w = MAXNUM + MAXNUM * I; + w = CMPLX(w, 0.25 * log(a)); return w; } --DKU6Jbt7q3WqK7+M--