From owner-freebsd-numerics@FreeBSD.ORG Sun Aug 5 19:40:57 2012 Return-Path: Delivered-To: freebsd-numerics@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id E7ED4106566B for ; Sun, 5 Aug 2012 19:40:57 +0000 (UTC) (envelope-from stephen@missouri.edu) Received: from wilberforce.math.missouri.edu (wilberforce.math.missouri.edu [128.206.184.213]) by mx1.freebsd.org (Postfix) with ESMTP id 90AEF8FC1A for ; Sun, 5 Aug 2012 19:40:57 +0000 (UTC) Received: from [127.0.0.1] (wilberforce.math.missouri.edu [128.206.184.213]) by wilberforce.math.missouri.edu (8.14.5/8.14.5) with ESMTP id q75JeuRj009888; Sun, 5 Aug 2012 14:40:56 -0500 (CDT) (envelope-from stephen@missouri.edu) Message-ID: <501ECC48.40001@missouri.edu> Date: Sun, 05 Aug 2012 14:40:56 -0500 From: Stephen Montgomery-Smith User-Agent: Mozilla/5.0 (X11; Linux i686; rv:14.0) Gecko/20120714 Thunderbird/14.0 MIME-Version: 1.0 To: Steve Kargl References: <5017111E.6060003@missouri.edu> <501C361D.4010807@missouri.edu> <20120804165555.X1231@besplex.bde.org> <501D51D7.1020101@missouri.edu> <20120805030609.R3101@besplex.bde.org> <501D9C36.2040207@missouri.edu> <20120805175106.X3574@besplex.bde.org> <501EC015.3000808@missouri.edu> <20120805191954.GA50379@troutmask.apl.washington.edu> In-Reply-To: <20120805191954.GA50379@troutmask.apl.washington.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Cc: freebsd-numerics@freebsd.org, Bruce Evans Subject: Re: Complex arg-trig functions 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: , X-List-Received-Date: Sun, 05 Aug 2012 19:40:58 -0000 On 08/05/2012 02:19 PM, Steve Kargl wrote: > On Sun, Aug 05, 2012 at 01:48:53PM -0500, Stephen Montgomery-Smith wrote: >> Let me say that in my proposed code for casinh, etc, that I do have >> essay length comments. >> http://people.freebsd.org/~stephen/catrig.c > > Essay long comments probably belong in the man page if the essay is > important to the details of implementation. Bruce may disagree with > me. Except that the comments cannot really be understood without the code, and vice versa. For example, there are places where I compute things like X+Y, and computing Y would cause an underflow, but I happen to know that Y is so much smaller than X that I only need to compute X. But the reason why I can be sure that Y is so much smaller than X is quite subtle - you have to read the code that generates X and the parts that make up Y to see why this is true. Look in my code for the phrase "This cannot happen" and look at the comment this phrase appears in, and the comment below it. It simply doesn't belong in a man page. But the arguments are of the nature of a mathematical proof, and if the arguments aren't presented somewhere, in my opinion the code would be incomprehensible. You could argue that the reader of the code could simply read the paper (*) I got the algorithm from. But I made significant deviations from the algorithm, not least because that paper used exception handling to handle underflows and overflows, whereas I detect them before they happen. Also, I defined the function, which I called f(a,b) = 0.5 * (hypot(a,b) - b) = 0.5*a*a/(hypot(a,b) + b) which was implicitly used several times in that paper, but never presented as a single concept. In my opinion the algorithm is not obvious, but it is also necessary, because numeric instability can occur in rather awkward ways. It isn't immediately obvious how to work around them. I thought the ideas in the paper were brilliant. I feel very strongly that my essay long comments should stay inside the code. I think I do a good job explaining a rather subtle algorithm, and I would hope that a reader could completely understand the algorithm by reading my code + comments. (*) "Implementing the complex arcsine and arccosine functions using exception handling" by T. E. Hull, Thomas F. Fairgrieve, and Ping Tak Peter Tang, published in ACM Transactions on Mathematical Software, Volume 23 Issue 3, 1997, Pages 299-335, http://dl.acm.org/citation.cfm?id=275324