From owner-freebsd-numerics@FreeBSD.ORG Sun Aug 12 23:06:23 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 D47A8106566B for ; Sun, 12 Aug 2012 23:06:23 +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 40EB38FC1B for ; Sun, 12 Aug 2012 23:06:22 +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 q7CN6M9j075707 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 13 Aug 2012 09:06:22 +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 q7CN6GOp021352 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 13 Aug 2012 09:06:16 +1000 (EST) (envelope-from peter@server.rulingia.com) Received: (from peter@localhost) by server.rulingia.com (8.14.5/8.14.5/Submit) id q7CN6G42021351 for freebsd-numerics@freebsd.org; Mon, 13 Aug 2012 09:06:16 +1000 (EST) (envelope-from peter) Resent-From: Peter Jeremy Resent-Date: Mon, 13 Aug 2012 09:06:16 +1000 Resent-Message-ID: <20120812230616.GX20453@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 q6HBanFE074433 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Tue, 17 Jul 2012 21:36:49 +1000 (EST) (envelope-from brde@optusnet.com.au) Received: from mail05.syd.optusnet.com.au (mail05.syd.optusnet.com.au [211.29.132.186]) by vps.rulingia.com (8.14.5/8.14.5) with ESMTP id q6HBanHI067069 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Tue, 17 Jul 2012 21:36:49 +1000 (EST) (envelope-from brde@optusnet.com.au) Received: from c122-106-171-246.carlnfd1.nsw.optusnet.com.au (c122-106-171-246.carlnfd1.nsw.optusnet.com.au [122.106.171.246]) by mail05.syd.optusnet.com.au (8.13.1/8.13.1) with ESMTP id q6HBaRkk002705 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Tue, 17 Jul 2012 21:36:28 +1000 From: Bruce Evans Mail-Followup-To: freebsd-numerics@freebsd.org X-X-Sender: bde@besplex.bde.org To: Bruce Evans In-Reply-To: <20120717200931.U6624@besplex.bde.org> Message-ID: <20120717211625.E6848@besplex.bde.org> References: <20120529045612.GB4445@server.rulingia.com> <20120711223247.GA9964@troutmask.apl.washington.edu> <20120713114100.GB83006@server.rulingia.com> <201207130818.38535.jhb@freebsd.org> <9EB2DA4F-19D7-4BA5-8811-D9451CB1D907@theravensnest.org> <20120713155805.GC81965@zim.MIT.EDU> <20120714120432.GA70706@server.rulingia.com> <20120717084457.U3890@besplex.bde.org> <5004A5C7.1040405@missouri.edu> <5004DEA9.1050001@missouri.edu> <20120717200931.U6624@besplex.bde.org> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII; format=flowed X-Mailman-Approved-At: Sun, 12 Aug 2012 23:55:59 +0000 Cc: Diane Bruce , John Baldwin , David Chisnall , Stephen Montgomery-Smith , Bruce Evans , Steve Kargl , David Schultz , Peter Jeremy , 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 23:06:23 -0000 X-Original-Date: Tue, 17 Jul 2012 21:36:27 +1000 (EST) X-List-Received-Date: Sun, 12 Aug 2012 23:06:23 -0000 On Tue, 17 Jul 2012, Bruce Evans wrote: > On Mon, 16 Jul 2012, Stephen Montgomery-Smith wrote: > >> On 07/16/2012 06:37 PM, Stephen Montgomery-Smith wrote: >>> ... >>> We might get lucky, and find that the definitions of csqrt and clog in >>> the C99 standard are already set up so that the naive formulas for >>> cacosh, etc, just work. But whether they do or whether they don't, I >>> think I can do it. (As a first guess, I think that catanh and casinh >>> will work "out of the box" but cacosh is going to take a bit more work.) > > See below what happened for naive formulars for ccosh. I forgot the below before. The following is ccosh() using mainly the naive formula. % /* % * Hyperbolic cosine of a double complex argument. % * % * Most exceptional values are automatically correctly handled by the % * standard formula. See n1124.pdf for details. % */ % % #include % #include % % #include "math_private.h" % % double complex % ccosh1(double complex z) % { % double x, y; % % x = creal(z); % y = cimag(z); % % /* % * This is subtler than it looks. We handle the cases x == 0 and % * y == 0 directly not for efficiency, but to avoid multiplications % * that don't work like we need. In these cases, the result must % * be almost pure real or a pure imaginary, except it has type % * float complex and its impure part may be -0. Multiplication of % * +-0 by an infinity or a NaN would give a NaN for the impure part, % * and would raise an unwanted exception. % * % * We depend on cos(y) and sin(y) never being precisely +-0 except % * when y is +-0 to prevent getting NaNs from other cases of % * +-Inf*+-0. This is true in infinite precision (since pi is % * irrational), and checking shows that it is also true after % * rounding to float precision. % */ % if (x == 0 && !isfinite(y)) % return (cpack(y - y, copysign(0, x * (y - y)))); % if (y == 0) % return (cpack(cosh(x), isnan(x) ? copysign(0, (x + x) * y) : % copysign(0, x) * y)); % if (isinf(x) && !isfinite(y)) % return (cpack(x * x, x * (y - y))); % if (fabs(x) > 710 && fabs(x) < 1455) { % z = __ldexp_cexp(cpack(fabs(x), y), -1); % return (cpack(creal(z), cimag(z) * copysign(1, x))); % } % return (cpack(cosh(x) * cos(y), sinh(x) * sin(y))); % } This was compared with the committed version and changed minimally to have the same behaviour for exceptional args. (Actually, more the reverse -- try the naive version and see what behaviour falls out of it for exceptional args. Then change both to match the behaviour specified in C99. This version was changed minimally to keep it as short as possible and the committed version was changed maximally to have at least a comment for all the exceptional cases.) One problem with this is that it is hard to see even what the exceptional cases are. Another is that the classification macros are very slow and only slightly easier to use than the bit-based classifications in the committed version (the latter could probably be macro-ized to make them almost as asy to use as the classification macros). I added the __ldexp_cexp() code later to maintain the binary compatibility of this with the comiitted version. So it's not using the naive formula for large |x|. Bruce