Update ENTERI() macro

Steve Kargl sgk at troutmask.apl.washington.edu
Mon Mar 4 21:31:42 UTC 2019


On Thu, Feb 28, 2019 at 07:15:14AM +1100, Bruce Evans wrote:
> On Wed, 27 Feb 2019, Steve Kargl wrote:
> 
> > On Wed, Feb 27, 2019 at 09:15:52PM +1100, Bruce Evans wrote:
> >>
> >> ENTERI() hard-codes the long double for simplicity.  Remember, it is only
> >> needed for long double precision on i386.  But I forgot about long double
> >> complex types, and didn't dream about indirect long double types in sincosl().
> >
> > That simplicity does not work for long double complex.  We will
> > 
> > need either ENTERIC as in
> >
> > #define ENTERIC() ENTERIT(long double complex)
> >
> > or a direct use of ENTERIT as you have done s_clogl.c
> 
> I wrote ENTERIT() to work around this problem.
> 
> >>> I'm fine with making ENTERI() only toggle precision, and adding
> >>> a LEAVEI() to reset precision.  RETURNI(r) would then be
> >>>
> >>> #define RETURNI(r)	\
> >>> do {		\
> >>>   LEAVEI();		\
> >>>   return (r);	\
> >>> } while (0)
> >>
> >> No, may be an expression, so it must be evaluated before LEAVEI().  This
> >> is the reason for existence of the variable to hold the result.
> >
> > So, we'll need RETURNI for long double and one for long double complex.
> > Or, we give RETURNI a second parameter, which is the input parameter of
> > the function
> 
> I said to use your method of __typeof().  I tested this:
> 
> XX --- /tmp/math_private.h	Sun Nov 27 17:58:57 2005
> XX +++ ./math_private.h	Thu Feb 28 06:17:26 2019
> XX @@ -474,21 +474,22 @@
> XX  /* Support switching the mode to FP_PE if necessary. */
> XX  #if defined(__i386__) && !defined(NO_FPSETPREC)
> XX -#define	ENTERI() ENTERIT(long double)
> XX -#define	ENTERIT(returntype)			\
> XX -	returntype __retval;			\
> XX +#define	ENTERI()				\
> XX  	fp_prec_t __oprec;			\
> XX  						\
> XX  	if ((__oprec = fpgetprec()) != FP_PE)	\
> XX  		fpsetprec(FP_PE)
> XX -#define	RETURNI(x) do {				\
> XX -	__retval = (x);				\
> XX -	if (__oprec != FP_PE)			\
> XX -		fpsetprec(__oprec);		\
> XX +#define	LEAVEI()				\
> XX +	if ((__oprec = fpgetprec()) != FP_PE)	\
> XX +		fpsetprec(FP_PE)

Am I reading this diff wrong?  Should LEAVEI() be

#define LEAVEI()			\
	if (__oprec != FP_PE)		\
		fpsetprec(__oprec)

That is, we want to reset the precision to what ENTERI
grabbed in its conditinal expression.

-- 
Steve
20170425 https://www.youtube.com/watch?v=VWUpyCsUKR4
20161221 https://www.youtube.com/watch?v=IbCHE-hONow


More information about the freebsd-numerics mailing list