13a8617a8SJordan K. Hubbard /*
23a8617a8SJordan K. Hubbard * ====================================================
33a8617a8SJordan K. Hubbard * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
43a8617a8SJordan K. Hubbard *
53a8617a8SJordan K. Hubbard * Developed at SunPro, a Sun Microsystems, Inc. business.
63a8617a8SJordan K. Hubbard * Permission to use, copy, modify, and distribute this
73a8617a8SJordan K. Hubbard * software is freely granted, provided that this notice
83a8617a8SJordan K. Hubbard * is preserved.
93a8617a8SJordan K. Hubbard * ====================================================
103a8617a8SJordan K. Hubbard */
113a8617a8SJordan K. Hubbard
123a8617a8SJordan K. Hubbard /*
133a8617a8SJordan K. Hubbard * double logb(x)
143a8617a8SJordan K. Hubbard * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
153a8617a8SJordan K. Hubbard * Use ilogb instead.
163a8617a8SJordan K. Hubbard */
173a8617a8SJordan K. Hubbard
186821aba9SDavid Schultz #include <float.h>
196821aba9SDavid Schultz
203a8617a8SJordan K. Hubbard #include "math.h"
213a8617a8SJordan K. Hubbard #include "math_private.h"
223a8617a8SJordan K. Hubbard
2300b1756bSBruce Evans static const double
2400b1756bSBruce Evans two54 = 1.80143985094819840000e+16; /* 43500000 00000000 */
2500b1756bSBruce Evans
2659b19ff1SAlfred Perlstein double
logb(double x)273819e840SPeter Wemm logb(double x)
283a8617a8SJordan K. Hubbard {
293a8617a8SJordan K. Hubbard int32_t lx,ix;
303a8617a8SJordan K. Hubbard EXTRACT_WORDS(ix,lx,x);
313a8617a8SJordan K. Hubbard ix &= 0x7fffffff; /* high |x| */
323a8617a8SJordan K. Hubbard if((ix|lx)==0) return -1.0/fabs(x);
333a8617a8SJordan K. Hubbard if(ix>=0x7ff00000) return x*x;
3400b1756bSBruce Evans if(ix<0x00100000) {
3500b1756bSBruce Evans x *= two54; /* convert subnormal x to normal */
36aa7c7c47SBruce Evans GET_HIGH_WORD(ix,x);
3700b1756bSBruce Evans ix &= 0x7fffffff;
38aa7c7c47SBruce Evans return (double) ((ix>>20)-1023-54);
3900b1756bSBruce Evans } else
4000b1756bSBruce Evans return (double) ((ix>>20)-1023);
413a8617a8SJordan K. Hubbard }
426821aba9SDavid Schultz
436821aba9SDavid Schultz #if (LDBL_MANT_DIG == 53)
446821aba9SDavid Schultz __weak_reference(logb, logbl);
456821aba9SDavid Schultz #endif
46