s_logb.c revision 153049
11573Srgrimes/* @(#)s_logb.c 5.1 93/09/24 */
21573Srgrimes/*
31573Srgrimes * ====================================================
41573Srgrimes * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
51573Srgrimes *
61573Srgrimes * Developed at SunPro, a Sun Microsystems, Inc. business.
71573Srgrimes * Permission to use, copy, modify, and distribute this
81573Srgrimes * software is freely granted, provided that this notice
91573Srgrimes * is preserved.
101573Srgrimes * ====================================================
111573Srgrimes */
121573Srgrimes
131573Srgrimes#ifndef lint
141573Srgrimesstatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_logb.c 153049 2005-12-03 11:57:19Z bde $";
151573Srgrimes#endif
161573Srgrimes
171573Srgrimes/*
181573Srgrimes * double logb(x)
191573Srgrimes * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
201573Srgrimes * Use ilogb instead.
211573Srgrimes */
221573Srgrimes
231573Srgrimes#include "math.h"
241573Srgrimes#include "math_private.h"
251573Srgrimes
261573Srgrimesstatic const double
271573Srgrimestwo54 = 1.80143985094819840000e+16;	/* 43500000 00000000 */
281573Srgrimes
291573Srgrimesdouble
301573Srgrimeslogb(double x)
311573Srgrimes{
321573Srgrimes	int32_t lx,ix;
331573Srgrimes	EXTRACT_WORDS(ix,lx,x);
341573Srgrimes	ix &= 0x7fffffff;			/* high |x| */
351573Srgrimes	if((ix|lx)==0) return -1.0/fabs(x);
361573Srgrimes	if(ix>=0x7ff00000) return x*x;
371573Srgrimes	if(ix<0x00100000) {
38103385Sbde		x *= two54;		 /* convert subnormal x to normal */
391573Srgrimes		GET_FLOAT_WORD(ix,x);
401573Srgrimes		ix &= 0x7fffffff;
411573Srgrimes		return (float) ((ix>>20)-1023-54);
42103385Sbde	} else
431573Srgrimes		return (double) ((ix>>20)-1023);
44103385Sbde}
45103385Sbde