From owner-freebsd-standards@FreeBSD.ORG Thu Oct 6 21:26:15 2005 Return-Path: X-Original-To: freebsd-standards@freebsd.org Delivered-To: freebsd-standards@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 9498C16A41F for ; Thu, 6 Oct 2005 21:26:15 +0000 (GMT) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (troutmask.apl.washington.edu [128.208.78.105]) by mx1.FreeBSD.org (Postfix) with ESMTP id CBDD443D53 for ; Thu, 6 Oct 2005 21:26:13 +0000 (GMT) (envelope-from sgk@troutmask.apl.washington.edu) Received: from troutmask.apl.washington.edu (localhost [127.0.0.1]) by troutmask.apl.washington.edu (8.13.4/8.13.4) with ESMTP id j96LQ8RO040870; Thu, 6 Oct 2005 14:26:08 -0700 (PDT) (envelope-from sgk@troutmask.apl.washington.edu) Received: (from sgk@localhost) by troutmask.apl.washington.edu (8.13.4/8.13.1/Submit) id j96LQ3ge040869; Thu, 6 Oct 2005 14:26:03 -0700 (PDT) (envelope-from sgk) Date: Thu, 6 Oct 2005 14:26:02 -0700 From: Steve Kargl To: Bruce Evans Message-ID: <20051006212602.GA40609@troutmask.apl.washington.edu> References: <20050929195552.GA14982@troutmask.apl.washington.edu> <20050930221846.T34595@delplex.bde.org> <20050930152734.GA20655@troutmask.apl.washington.edu> <20051001204005.N37704@delplex.bde.org> <20051002191841.GA40568@troutmask.apl.washington.edu> <20051004164618.U47262@delplex.bde.org> <20051005032400.GA6736@troutmask.apl.washington.edu> <20051005191936.N51036@delplex.bde.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051005191936.N51036@delplex.bde.org> User-Agent: Mutt/1.4.2.1i Cc: freebsd-standards@freebsd.org Subject: Re: complex.h math functions X-BeenThere: freebsd-standards@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Standards compliance List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 06 Oct 2005 21:26:15 -0000 On Wed, Oct 05, 2005 at 08:16:03PM +1000, Bruce Evans wrote: > On Tue, 4 Oct 2005, Steve Kargl wrote: > > >On Tue, Oct 04, 2005 at 07:31:43PM +1000, Bruce Evans wrote: > >>On Sun, 2 Oct 2005, Steve Kargl wrote: > > > >>I converted to ccoshf() for testing it and comparing with a simpler > >>implementation that uses the formula, then converted back. There are > > >So which implementation do you prefer: your simpler version or > >your fixed version of my first cut at ccosh? > > If course I prefer the simpler version :-). I think version that handles > all the exceptional cases explicitly is useful mainly for bootstrapping. I've implemented some inline functions (see below) for the assignments of the real and imaginary parts. After replacing creal(f) = cosh(x) * cos(y); cimag(f) = sinh(x) * sin(y); return (f); in your simpler function by return (cmplx(cosh(x) * cos(y), sinh(x) * sin(y)); your test program is generating a large number of z = 0x7f800000+I0x7fa00000 inf+Inan ccosh(z) = 0x7f800000+I0x7fe00000 inf+Inan ccosh1(z) = 0x7fe00000+I0x7fe00000 nan+Inan err = +0x600000+I+.0 where ccosh1 is your simpler function and ccosh is your fixed version of my ccosh (both have been converted to use the inline functions). n869.pdf says ccosh(inf+Inan) = inf+Inan > >>Handle x == 0, y finite. There are 2 unobvious details: > >>- getting the sign right when y == 0... > >> > >>% + creal(f) = cos(y); > >>% + cimag(f) = x * con; > >>% + return f; > > > >Wow. I'm used to programming in Fortran and would never have > >written "creal(f) = ...". This looks like your assigning a > >value to a function. (For those in the peanut gallery that > >snicker at the mention of Fortran, please see the Fortran 2003 > >standard.) Apparently, my version of gcc does not like the above code. How did you compile your s_ccosh1.c? > >If we go the macro route, do you want it (them?) in math_private.h > >or complex.h? If creal(f) appears on the LHS, is it a generic > >reference so that type is forced to match the RHS? Is > > > >#define CMPLX((z),(x),(y)) {creal((z)) = (x), cimag((z)) = (y)} > > > >acceptable? > > I think it should go in math_private.h only and be an inline function. --- /mnt1/src/lib/msun/src/math_private.h Fri Feb 4 12:05:39 2005 +++ ../math_private.h Thu Oct 6 14:06:37 2005 @@ -155,6 +155,43 @@ } while (0) /* + * Inline functions that can be used to construct complex values. + */ + +static __inline float complex +cmplxf(float __x, float __y) +{ + float *__ptr; + float complex __z; + __ptr = (float *) &__z; + *__ptr++ = __x; + *__ptr = __y; + return (__z); +} + +static __inline double complex +cmplx(double __x, double __y) +{ + double *__ptr; + double complex __z; + __ptr = (double *) &__z; + *__ptr++ = __x; + *__ptr = __y; + return (__z); +} + +static __inline long double complex +cmplxl(long double __x, long double __y) +{ + long double *__ptr; + long double complex __z; + __ptr = (long double *) &__z; + *__ptr++ = __x; + *__ptr = __y; + return (__z); +} + +/* * ieee style elementary functions * * We rename functions here to improve other sources' diffability -- Steve