Home | History | Annotate | Line # | Download | only in src
s_logb.c revision 1.12
      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.10  simonb  * 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.12   joerg __RCSID("$NetBSD: s_logb.c,v 1.12 2011/08/03 14:13:07 joerg 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.12   joerg #ifndef __HAVE_LONG_DOUBLE
     28  1.12   joerg __strong_alias(logbl,logb)
     29  1.12   joerg #endif
     30  1.12   joerg 
     31  1.11     wiz double
     32  1.11     wiz logb(double x)
     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.10  simonb 		return -1022.0;
     41   1.1     jtc 	else
     42  1.10  simonb 		return (double) (ix-1023);
     43   1.1     jtc }
     44