s_logb.c revision 153049
12116Sjkh/* @(#)s_logb.c 5.1 93/09/24 */
22116Sjkh/*
32116Sjkh * ====================================================
42116Sjkh * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
52116Sjkh *
62116Sjkh * Developed at SunPro, a Sun Microsystems, Inc. business.
72116Sjkh * Permission to use, copy, modify, and distribute this
88870Srgrimes * software is freely granted, provided that this notice
92116Sjkh * is preserved.
102116Sjkh * ====================================================
112116Sjkh */
122116Sjkh
132116Sjkh#ifndef lint
1450476Speterstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_logb.c 153049 2005-12-03 11:57:19Z bde $";
152116Sjkh#endif
162116Sjkh
172116Sjkh/*
182116Sjkh * double logb(x)
192116Sjkh * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
202116Sjkh * Use ilogb instead.
212116Sjkh */
222116Sjkh
232116Sjkh#include "math.h"
242116Sjkh#include "math_private.h"
252116Sjkh
26153049Sbdestatic const double
27153049Sbdetwo54 = 1.80143985094819840000e+16;	/* 43500000 00000000 */
28153049Sbde
2997413Salfreddouble
30117912Speterlogb(double x)
312116Sjkh{
322116Sjkh	int32_t lx,ix;
332116Sjkh	EXTRACT_WORDS(ix,lx,x);
342116Sjkh	ix &= 0x7fffffff;			/* high |x| */
352116Sjkh	if((ix|lx)==0) return -1.0/fabs(x);
362116Sjkh	if(ix>=0x7ff00000) return x*x;
37153049Sbde	if(ix<0x00100000) {
38153049Sbde		x *= two54;		 /* convert subnormal x to normal */
39153049Sbde		GET_FLOAT_WORD(ix,x);
40153049Sbde		ix &= 0x7fffffff;
41153049Sbde		return (float) ((ix>>20)-1023-54);
42153049Sbde	} else
43153049Sbde		return (double) ((ix>>20)-1023);
442116Sjkh}
45