From owner-freebsd-numerics@FreeBSD.ORG Fri Aug 3 20:35:47 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 C90B1106566B for ; Fri, 3 Aug 2012 20:35:47 +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 8E1438FC0A for ; Fri, 3 Aug 2012 20:35:47 +0000 (UTC) Received: from [128.206.184.213] (wilberforce.math.missouri.edu [128.206.184.213]) by wilberforce.math.missouri.edu (8.14.5/8.14.5) with ESMTP id q73KZfD0087564 for ; Fri, 3 Aug 2012 15:35:41 -0500 (CDT) (envelope-from stephen@missouri.edu) Message-ID: <501C361D.4010807@missouri.edu> Date: Fri, 03 Aug 2012 15:35:41 -0500 From: Stephen Montgomery-Smith User-Agent: Mozilla/5.0 (X11; FreeBSD amd64; rv:14.0) Gecko/20120728 Thunderbird/14.0 MIME-Version: 1.0 To: freebsd-numerics@freebsd.org References: <5017111E.6060003@missouri.edu> In-Reply-To: <5017111E.6060003@missouri.edu> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit 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: Fri, 03 Aug 2012 20:35:47 -0000 On 07/30/12 17:56, Stephen Montgomery-Smith wrote: > I will be posting my updates on this web page: > > http://people.freebsd.org/~stephen/ > > The file catrig.c contains implementations of cacos(h), casin(h), > catan(h). I have been working on it everyday - I seem unable to put it > down. I know you guys are busy and haven't had time to look this over. But in many ways this is a good thing, as I am constantly finding problems with the code. One of the hardest things is trying to avoid unwarranted underflows. For example, when |z| is large (bigger than 1e20) I use the approximation catanh(z) = 1/z + cpack(0, copysign(M_PI_2, cimag(z))) If the real part of 1/z underflows, then this is a legitimate underflow. But if the imaginary part of 1/z underflows, then this is not legitimate, because then this really small number is being added to plus or minus I*PI/2, and it should just disappear into rounding error. I found this out by testing the underflow flag for lots of random inputs. I ended up writing my own code to compute the real part of 1/z without computing the imaginary part. I have a working solution, but I'm sure it isn't optimal. (I see there is code in the IEEE standard PDF document which I might copy, or I might copy ideas from the hypot function.) Another problem I experienced - I sometimes need to compute log(0.5*y) when x is extremely small. I was shocked to find that this produced spurious underflows when x was very close to DBL_MIN. Of course with hindsight it is obvious why it happens, but these errors are hard to think of in advance, and hard to track down. Right now I think I have working code. But I also thought I had working code last week. So who knows. Anyway, thanks for reading my ramblings. I do find this stuff interesting, so if anyone wants to reply and continue the conversation, please do so. Stephen