Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 6 Oct 2005 14:26:02 -0700
From:      Steve Kargl <sgk@troutmask.apl.washington.edu>
To:        Bruce Evans <bde@zeta.org.au>
Cc:        freebsd-standards@freebsd.org
Subject:   Re: complex.h math functions
Message-ID:  <20051006212602.GA40609@troutmask.apl.washington.edu>
In-Reply-To: <20051005191936.N51036@delplex.bde.org>
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>

next in thread | previous in thread | raw e-mail | index | archive | help
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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20051006212602.GA40609>