• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 
2 /* @(#)s_ilogb.c 1.3 95/01/18 */
3 /*
4  * ====================================================
5  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6  *
7  * Developed at SunSoft, a Sun Microsystems, Inc. business.
8  * Permission to use, copy, modify, and distribute this
9  * software is freely granted, provided that this notice
10  * is preserved.
11  * ====================================================
12  */
13 
14 /* ieee_ilogb(double x)
15  * return the binary exponent of non-zero x
16  * ieee_ilogb(0) = 0x80000001
17  * ieee_ilogb(inf/NaN) = 0x7fffffff (no signal is raised)
18  */
19 
20 #include "fdlibm.h"
21 
22 #ifdef __STDC__
ieee_ilogb(double x)23 	int ieee_ilogb(double x)
24 #else
25 	int ieee_ilogb(x)
26 	double x;
27 #endif
28 {
29 	int hx,lx,ix;
30 
31 	hx  = (__HI(x))&0x7fffffff;	/* high word of x */
32 	if(hx<0x00100000) {
33 	    lx = __LO(x);
34 	    if((hx|lx)==0)
35 		return 0x80000001;	/* ieee_ilogb(0) = 0x80000001 */
36 	    else			/* subnormal x */
37 		if(hx==0) {
38 		    for (ix = -1043; lx>0; lx<<=1) ix -=1;
39 		} else {
40 		    for (ix = -1022,hx<<=11; hx>0; hx<<=1) ix -=1;
41 		}
42 	    return ix;
43 	}
44 	else if (hx<0x7ff00000) return (hx>>20)-1023;
45 	else return 0x7fffffff;
46 }
47