2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_ilogbl.c
blob428854d77036d6b8c0b009da69269726a449beee
1 /* s_ilogbl.c -- long double version of s_ilogb.c.
2 * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
3 */
5 /*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 * Developed at SunPro, a Sun Microsystems, Inc. business.
10 * Permission to use, copy, modify, and distribute this
11 * software is freely granted, provided that this notice
12 * is preserved.
13 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
20 /* ilogbl(long double x)
21 * return the binary exponent of non-zero x
22 * ilogbl(0) = FP_ILOGB0
23 * ilogbl(NaN) = FP_ILOGBNAN (no signal is raised)
24 * ilogbl(+-Inf) = INT_MAX (no signal is raised)
27 #include <limits.h>
28 #include "math.h"
29 #include "math_private.h"
30 #include <math_ldbl_opt.h>
32 #ifdef __STDC__
33 int __ilogbl(long double x)
34 #else
35 int __ilogbl(x)
36 long double x;
37 #endif
39 int64_t hx,lx;
40 int ix;
42 GET_LDOUBLE_WORDS64(hx,lx,x);
43 hx &= 0x7fffffffffffffffLL;
44 if(hx <= 0x0010000000000000LL) {
45 if((hx|(lx&0x7fffffffffffffffLL))==0)
46 return FP_ILOGB0; /* ilogbl(0) = FP_ILOGB0 */
47 else /* subnormal x */
48 if(hx==0) {
49 for (ix = -1043; lx>0; lx<<=1) ix -=1;
50 } else {
51 for (ix = -1022, hx<<=11; hx>0; hx<<=1) ix -=1;
53 return ix;
55 else if (hx<0x7ff0000000000000LL) return (hx>>52)-0x3ff;
56 else if (FP_ILOGBNAN != INT_MAX) {
57 /* ISO C99 requires ilogbl(+-Inf) == INT_MAX. */
58 if (((hx^0x7ff0000000000000LL)|lx) == 0)
59 return INT_MAX;
61 return FP_ILOGBNAN;
63 long_double_symbol (libm, __ilogbl, ilogbl);