Home | History | Annotate | Line # | Download | only in src
s_logb.c revision 1.9
      1  1.1    jtc /* @(#)s_logb.c 5.1 93/09/24 */
      2  1.1    jtc /*
      3  1.1    jtc  * ====================================================
      4  1.1    jtc  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
      5  1.1    jtc  *
      6  1.1    jtc  * Developed at SunPro, a Sun Microsystems, Inc. business.
      7  1.1    jtc  * Permission to use, copy, modify, and distribute this
      8  1.1    jtc  * software is freely granted, provided that this notice
      9  1.1    jtc  * is preserved.
     10  1.1    jtc  * ====================================================
     11  1.1    jtc  */
     12  1.3    jtc 
     13  1.9  lukem #include <sys/cdefs.h>
     14  1.7    jtc #if defined(LIBM_SCCS) && !defined(lint)
     15  1.9  lukem __RCSID("$NetBSD: s_logb.c,v 1.9 1997/10/09 11:32:48 lukem Exp $");
     16  1.3    jtc #endif
     17  1.1    jtc 
     18  1.1    jtc /*
     19  1.1    jtc  * double logb(x)
     20  1.1    jtc  * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
     21  1.1    jtc  * Use ilogb instead.
     22  1.1    jtc  */
     23  1.1    jtc 
     24  1.5    jtc #include "math.h"
     25  1.5    jtc #include "math_private.h"
     26  1.1    jtc 
     27  1.1    jtc #ifdef __STDC__
     28  1.1    jtc 	double logb(double x)
     29  1.1    jtc #else
     30  1.1    jtc 	double logb(x)
     31  1.1    jtc 	double x;
     32  1.1    jtc #endif
     33  1.1    jtc {
     34  1.6    jtc 	int32_t lx,ix;
     35  1.5    jtc 	EXTRACT_WORDS(ix,lx,x);
     36  1.5    jtc 	ix &= 0x7fffffff;			/* high |x| */
     37  1.1    jtc 	if((ix|lx)==0) return -1.0/fabs(x);
     38  1.1    jtc 	if(ix>=0x7ff00000) return x*x;
     39  1.1    jtc 	if((ix>>=20)==0) 			/* IEEE 754 logb */
     40  1.1    jtc 		return -1022.0;
     41  1.1    jtc 	else
     42  1.1    jtc 		return (double) (ix-1023);
     43  1.1    jtc }
     44