pregen: Fix the parallel build problem in pregen target
[uclibc-ng.git] / libm / s_ilogb.c
blobce3029667a5f96bc6e2b250f4a69549d2dcdd9ec
1 /*
2 * ====================================================
3 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
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)
18 #include "math.h"
19 #include "math_private.h"
21 int ilogb(double x)
23 int32_t hx,lx,ix;
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;
37 return ix;
39 else if (hx<0x7ff00000) return (hx>>20)-1023;
40 else return 0x7fffffff;
42 libm_hidden_def(ilogb)