]> git.ipfire.org Git - thirdparty/glibc.git/blob - sysdeps/ieee754/ldbl-96/s_ilogbl.c
There is no legitimate reason to override reg_char on sparc32.
[thirdparty/glibc.git] / sysdeps / ieee754 / ldbl-96 / s_ilogbl.c
1 /* s_ilogbl.c -- long double version of s_ilogb.c.
2 * Conversion to long double by Ulrich Drepper,
3 * Cygnus Support, drepper@cygnus.com.
4 */
5
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
9 *
10 * Developed at SunPro, a Sun Microsystems, Inc. business.
11 * Permission to use, copy, modify, and distribute this
12 * software is freely granted, provided that this notice
13 * is preserved.
14 * ====================================================
15 */
16
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
20
21 /* ilogbl(long double x)
22 * return the binary exponent of non-zero x
23 * ilogbl(0) = FP_ILOGB0
24 * ilogbl(NaN) = FP_ILOGBNAN (no signal is raised)
25 * ilogbl(+-Inf) = INT_MAX (no signal is raised)
26 */
27
28 #include <limits.h>
29 #include <math.h>
30 #include <math_private.h>
31
32 int __ilogbl(long double x)
33 {
34 int32_t es,hx,lx,ix;
35
36 GET_LDOUBLE_EXP(es,x);
37 es &= 0x7fff;
38 if(es==0) {
39 GET_LDOUBLE_WORDS(es,hx,lx,x);
40 if((hx|lx)==0)
41 return FP_ILOGB0; /* ilogbl(0) = FP_ILOGB0 */
42 else /* subnormal x */
43 if(hx==0) {
44 for (ix = -16415; lx>0; lx<<=1) ix -=1;
45 } else {
46 for (ix = -16383; hx>0; hx<<=1) ix -=1;
47 }
48 return ix;
49 }
50 else if (es<0x7fff) return es-0x3fff;
51 else if (FP_ILOGBNAN != INT_MAX)
52 {
53 GET_LDOUBLE_WORDS(es,hx,lx,x);
54 if (((hx & 0x7fffffff)|lx) == 0)
55 /* ISO C99 requires ilogbl(+-Inf) == INT_MAX. */
56 return INT_MAX;
57 }
58 return FP_ILOGBNAN;
59 }
60 weak_alias (__ilogbl, ilogbl)