2.9
[glibc/nacl-glibc.git] / sysdeps / ieee754 / ldbl-128 / s_ilogbl.c
blobfe14395adc5741dee51777caad73c50051a0949f
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"
31 #ifdef __STDC__
32 int __ilogbl(long double x)
33 #else
34 int __ilogbl(x)
35 long double x;
36 #endif
38 int64_t hx,lx;
39 int ix;
41 GET_LDOUBLE_WORDS64(hx,lx,x);
42 hx &= 0x7fffffffffffffffLL;
43 if(hx <= 0x0001000000000000LL) {
44 if((hx|lx)==0)
45 return FP_ILOGB0; /* ilogbl(0) = FP_ILOGB0 */
46 else /* subnormal x */
47 if(hx==0) {
48 for (ix = -16431; lx>0; lx<<=1) ix -=1;
49 } else {
50 for (ix = -16382, hx<<=15; hx>0; hx<<=1) ix -=1;
52 return ix;
54 else if (hx<0x7fff000000000000LL) return (hx>>48)-0x3fff;
55 else if (FP_ILOGBNAN != INT_MAX) {
56 /* ISO C99 requires ilogbl(+-Inf) == INT_MAX. */
57 if (((hx^0x7fff000000000000LL)|lx) == 0)
58 return INT_MAX;
60 return FP_ILOGBNAN;
62 weak_alias (__ilogbl, ilogbl)