OSDN Git Service

mips/sysdep.h: Unify mips sysdep.h
[uclinux-h8/uClibc.git] / libm / s_ilogb.c
1 /*
2  * ====================================================
3  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
4  *
5  * Developed at SunPro, a Sun Microsystems, Inc. business.
6  * Permission to use, copy, modify, and distribute this
7  * software is freely granted, provided that this notice
8  * is preserved.
9  * ====================================================
10  */
11
12 /* ilogb(double x)
13  * return the binary exponent of non-zero x
14  * ilogb(0) = 0x80000001
15  * ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
16  */
17
18 #include "math.h"
19 #include "math_private.h"
20
21 int ilogb(double x)
22 {
23         int32_t hx,lx,ix;
24
25         GET_HIGH_WORD(hx,x);
26         hx &= 0x7fffffff;
27         if(hx<0x00100000) {
28             GET_LOW_WORD(lx,x);
29             if((hx|lx)==0)
30                 return 0x80000001;      /* ilogb(0) = 0x80000001 */
31             else                        /* subnormal x */
32                 if(hx==0) {
33                     for (ix = -1043; lx>0; lx<<=1) ix -=1;
34                 } else {
35                     for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
36                 }
37             return ix;
38         }
39         else if (hx<0x7ff00000) return (hx>>20)-1023;
40         else return 0x7fffffff;
41 }
42 libm_hidden_def(ilogb)