Update.
[glibc.git] / sysdeps / libm-ieee754 / s_ilogbl.c
blobd44229dcdac44e170daa844ea5fd433ceae5a610
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 */
6 /*
7 * ====================================================
8 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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 * ====================================================
17 #if defined(LIBM_SCCS) && !defined(lint)
18 static char rcsid[] = "$NetBSD: $";
19 #endif
21 /* ilogbl(long double x)
22 * return the binary exponent of non-zero x
23 * ilogbl(0) = 0x80000001
24 * ilogbl(inf/NaN) = 0x7fffffff (no signal is raised)
27 #include "math.h"
28 #include "math_private.h"
30 #ifdef __STDC__
31 int __ilogbl(long double x)
32 #else
33 int __ilogbl(x)
34 long double x;
35 #endif
37 int32_t es,hx,lx,ix;
39 GET_LDOUBLE_EXP(es,x);
40 es &= 0x7fff;
41 if(es==0) {
42 GET_LDOUBLE_WORDS(es,hx,lx,x);
43 if((hx|lx)==0)
44 return FP_ILOGB0; /* ilogbl(0) = FP_ILOGB0 */
45 else /* subnormal x */
46 if(hx==0) {
47 for (ix = -16415; lx>0; lx<<=1) ix -=1;
48 } else {
49 for (ix = -16383; hx>0; hx<<=1) ix -=1;
51 return ix;
53 else if (es<0x7fff) return es-0x3fff;
54 else return FP_ILOGBNAN;
56 weak_alias (__ilogbl, ilogbl)