From owner-freebsd-numerics@FreeBSD.ORG Sun Aug 12 22:57:45 2012 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 8DCAA1065675 for ; Sun, 12 Aug 2012 22:57:45 +0000 (UTC) (envelope-from peter@rulingia.com) Received: from vps.rulingia.com (host-122-100-2-194.octopus.com.au [122.100.2.194]) by mx1.freebsd.org (Postfix) with ESMTP id EEDBD8FC1D for ; Sun, 12 Aug 2012 22:57:44 +0000 (UTC) Received: from server.rulingia.com (c220-239-249-137.belrs5.nsw.optusnet.com.au [220.239.249.137]) by vps.rulingia.com (8.14.5/8.14.5) with ESMTP id q7CMviXl075503 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 13 Aug 2012 08:57:44 +1000 (EST) (envelope-from peter@rulingia.com) X-Bogosity: Ham, spamicity=0.000000 Received: from server.rulingia.com (localhost.rulingia.com [127.0.0.1]) by server.rulingia.com (8.14.5/8.14.5) with ESMTP id q7CMvc3F020885 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 13 Aug 2012 08:57:38 +1000 (EST) (envelope-from peter@server.rulingia.com) Received: (from peter@localhost) by server.rulingia.com (8.14.5/8.14.5/Submit) id q7CMvcqD020884 for freebsd-numerics@freebsd.org; Mon, 13 Aug 2012 08:57:38 +1000 (EST) (envelope-from peter) Resent-From: Peter Jeremy Resent-Date: Mon, 13 Aug 2012 08:57:38 +1000 Resent-Message-ID: <20120812225738.GH20453@server.rulingia.com> Resent-To: freebsd-numerics@freebsd.org Received: from vps.rulingia.com (host-122-100-2-194.octopus.com.au [122.100.2.194]) by server.rulingia.com (8.14.5/8.14.5) with ESMTP id q6HNRjuA088033 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 18 Jul 2012 09:27:46 +1000 (EST) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.95.76.21]) by vps.rulingia.com (8.14.5/8.14.5) with ESMTP id q6HNRh0G070533 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Wed, 18 Jul 2012 09:27:45 +1000 (EST) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost.apl.washington.edu [127.0.0.1]) by troutmask.apl.washington.edu (8.14.5/8.14.5) with ESMTP id q6HNRfrV095081; Tue, 17 Jul 2012 16:27:41 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.14.5/8.14.5/Submit) id q6HNReZG095080; Tue, 17 Jul 2012 16:27:40 -0700 (PDT) (envelope-from sgk) From: Steve Kargl Mail-Followup-To: freebsd-numerics@freebsd.org To: Peter Jeremy Message-ID: <20120717232740.GA95026@troutmask.apl.washington.edu> References: <20120713155805.GC81965@zim.MIT.EDU> <20120714120432.GA70706@server.rulingia.com> <20120717084457.U3890@besplex.bde.org> <5004A5C7.1040405@missouri.edu> <5004DEA9.1050001@missouri.edu> <20120717040118.GA86840@troutmask.apl.washington.edu> <20120717042125.GF66913@server.rulingia.com> <20120717043848.GB87001@troutmask.apl.washington.edu> <20120717225328.GA86902@server.rulingia.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20120717225328.GA86902@server.rulingia.com> User-Agent: Mutt/1.4.2.3i Cc: Diane Bruce , John Baldwin , David Chisnall , Stephen Montgomery-Smith , Bruce Evans , Bruce Evans , David Schultz , Warner Losh Subject: Re: Use of C99 extra long double math functions after r236148 X-BeenThere: freebsd-numerics@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Discussions of high quality implementation of libm functions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Date: Sun, 12 Aug 2012 22:57:45 -0000 X-Original-Date: Tue, 17 Jul 2012 16:27:40 -0700 X-List-Received-Date: Sun, 12 Aug 2012 22:57:45 -0000 On Wed, Jul 18, 2012 at 08:53:28AM +1000, Peter Jeremy wrote: > On 2012-Jul-16 21:38:48 -0700, Steve Kargl wrote: > >On Tue, Jul 17, 2012 at 02:21:25PM +1000, Peter Jeremy wrote: > >> Again, handling the special cases listed in G.6 is all just > >> boilerplate code that we can take as assumed for pseudocode. IMO, it > > > >As someone who spent 10+ years getting sqrtl(), cbrtl(), ccosh(), sinl(), > >cosl(), tanl(), etc into FreeBSD, I respectfully disagree with your > >take that it is just boilerplate. Getting this stuff right is much harder > >than I think some people understand. Oh well, I'll back to lurking and > >working on things I need. > > OK. I'll admit that I haven't tried this before but attached is my > first try at catan[h](). It should cover all the special casing > according to WG14/N1256 and compiles if you add the relevant > declarations to complex.h. I'd appreciate feedback. > > Notes on it: > - The actual code at the end of catanh() is just one possible > algorithm. It's not intended as final code and the final code is > likely to need additional special case handling to minimise > precision loss and prevent unwanted exceptions. > - cpack(-cimag(r), -creal(r)) gives better code than > -cpack(cimag(r), creal(r)) on i386 and identical code on amd64. > - The fpclassify() macros are bitmasks on FreeBSD. Assuming this > would allow (ci == FP_ZERO || ci == FP_NAN) to be simplified but the > standard only requires that they have distinct values and (eg) > Solaris implements them as a series so the current code is more > portable. > I won't have time to go over the code in detail until this weekend, but a quick peek showed some issues. The first is style. Although fdlibm has a rather interest coding style, new code should use KNF. /* * Calculate complex arc tangent using the identity: * catan(z) = -i catanh(iz) */ double complex catan(double complex z) { complex double r; r = catanh(cpack(cimag(z), creal(z))); I think you're missing a sign. Let z = x + i*y. Then, i*z = i*x+i*i*y = -y + i*x, yielding r = catanh(cpack(-cimag(z), creal(z))); return (cpack(-cimag(r), -creal(r))); Again, it seems a sign error has occurred. Let catanh(i*z) = u + i*v. Then, you have -i*catanh(i*z) = -i*u-i*i*v = v-i*u, yielding return (cpack(cimag(r), -creal(r))); } Of coure, I could be wrong. -- Steve