Back to index

glibc  2.9
s_logb.c
Go to the documentation of this file.
00001 /* @(#)s_logb.c 5.1 93/09/24 */
00002 /*
00003  * ====================================================
00004  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
00005  *
00006  * Developed at SunPro, a Sun Microsystems, Inc. business.
00007  * Permission to use, copy, modify, and distribute this
00008  * software is freely granted, provided that this notice
00009  * is preserved.
00010  * ====================================================
00011  */
00012 
00013 #if defined(LIBM_SCCS) && !defined(lint)
00014 static char rcsid[] = "$NetBSD: s_logb.c,v 1.8 1995/05/10 20:47:50 jtc Exp $";
00015 #endif
00016 
00017 /*
00018  * double logb(x)
00019  * IEEE 754 logb. Included to pass IEEE test suite. Not recommend.
00020  * Use ilogb instead.
00021  */
00022 
00023 #include "math.h"
00024 #include "math_private.h"
00025 
00026 #ifdef __STDC__
00027        double __logb(double x)
00028 #else
00029        double __logb(x)
00030        double x;
00031 #endif
00032 {
00033        int32_t lx,ix;
00034        EXTRACT_WORDS(ix,lx,x);
00035        ix &= 0x7fffffff;                  /* high |x| */
00036        if((ix|lx)==0) return -1.0/fabs(x);
00037        if(ix>=0x7ff00000) return x*x;
00038        if((ix>>=20)==0)                   /* IEEE 754 logb */
00039               return -1022.0;
00040        else
00041               return (double) (ix-1023);
00042 }
00043 weak_alias (__logb, logb)
00044 #ifdef NO_LONG_DOUBLE
00045 strong_alias (__logb, __logbl)
00046 weak_alias (__logb, logbl)
00047 #endif