Use of C99 extra long double math functions after r236148
Steve Kargl
sgk at troutmask.apl.washington.edu
Sun Aug 12 22:58:22 UTC 2012
On Fri, Jul 20, 2012 at 07:39:44AM +1000, Peter Jeremy wrote:
> On 2012-Jul-18 14:01:42 +1000, Bruce Evans <brde at optusnet.com.au> wrote:
>
> >The standard classification macros are good for developing things, but
> >they are very slow. All (?) committed complex functions use hard-coded
> >bit test.
>
> I notice that the functions are full of hard-coded magic constants.
> Would these be better as macros to:
> 1) Provide a description as to their purpose; and
> 2) Reduce differences between the float/long/double function bodies?
>
I collected some of the float and double into a cheat sheet.
Idioms used in libm with float type:
int32_t xsb;
u_int32_t hx;
GET_FLOAT_WORD(hx, x);
/* Get the sign bit of x */
xsb = (hx >> 31) & 1;
/* high word of |x| */
hx &= 0x7fffffff;
/* NaN */
if (hx > 0x7f800000)
return (x + x);
/* exp(+-inf) = {inf, 0} */
if (hx == 0x7f800000)
return (xsb == 0) ? x : 0.0;
/* subnormal */
if (hx < 0x00800000)
Idioms used in lib with double type:
u_int32_t hx, lx, xsb
EXTRACT_WORDS(hx, lx, x);
/* sign bit of x */
xsb = (hx >> 31) & 1;
/* high word of |x| */
hx &= 0x7fffffff;
/* subnormal */
if (hx < 0x00100000)
/* Test for NaN and +-Inf. */
if (hx >= 0x7ff00000) {
/* Is it a NaN? */
if (((hx & 0xfffff) | lx) != 0)
return (x + x);
/* It's an +-Inf. */
return ((xsb == 0) ? x : 0.0); /* exp(+-inf)={inf,0} */
}
--
Steve
More information about the freebsd-numerics
mailing list