Home | History | Annotate | Line # | Download | only in src
s_logb.c revision 1.1
      1  1.1  jtc 
      2  1.1  jtc /* @(#)s_logb.c 5.1 93/09/24 */
      3  1.1  jtc /*
      4  1.1  jtc  * ====================================================
      5  1.1  jtc  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
      6  1.1  jtc  *
      7  1.1  jtc  * Developed at SunPro, a Sun Microsystems, Inc. business.
      8  1.1  jtc  * Permission to use, copy, modify, and distribute this
      9  1.1  jtc  * software is freely granted, provided that this notice
     10  1.1  jtc  * is preserved.
     11  1.1  jtc  * ====================================================
     12  1.1  jtc  */
     13  1.1  jtc 
     14  1.1  jtc /*
     15  1.1  jtc  * double logb(x)
     16  1.1  jtc  * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
     17  1.1  jtc  * Use ilogb instead.
     18  1.1  jtc  */
     19  1.1  jtc 
     20  1.1  jtc #include "fdlibm.h"
     21  1.1  jtc 
     22  1.1  jtc #ifdef __STDC__
     23  1.1  jtc static const double one = 1.0;
     24  1.1  jtc #else
     25  1.1  jtc static double one = 1.0;
     26  1.1  jtc #endif
     27  1.1  jtc 
     28  1.1  jtc #ifdef __STDC__
     29  1.1  jtc 	double logb(double x)
     30  1.1  jtc #else
     31  1.1  jtc 	double logb(x)
     32  1.1  jtc 	double x;
     33  1.1  jtc #endif
     34  1.1  jtc {
     35  1.1  jtc 	int n0,lx,ix;
     36  1.1  jtc 	n0 = ((*(int*)&one)>>29)^1;
     37  1.1  jtc 	ix = (*(n0+(int*)&x))&0x7fffffff;	/* high |x| */
     38  1.1  jtc 	lx = *(1-n0+(int*)&x);			/* low x */
     39  1.1  jtc 	if((ix|lx)==0) return -1.0/fabs(x);
     40  1.1  jtc 	if(ix>=0x7ff00000) return x*x;
     41  1.1  jtc 	if((ix>>=20)==0) 			/* IEEE 754 logb */
     42  1.1  jtc 		return -1022.0;
     43  1.1  jtc 	else
     44  1.1  jtc 		return (double) (ix-1023);
     45  1.1  jtc }
     46