1/* s_ilogbl.c -- long double version of s_ilogb.c.
2 * Conversion to 80-bit long double by Mark Kettenis, kettenis@openbsd.org.
3 */
4
5/*
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8 *
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 * ====================================================
14 */
15
16/* ilogbl(long double x)
17 * return the binary exponent of non-zero x
18 * ilogb(0) = FP_ILOGB0
19 * ilogb(NaN) = FP_ILOGBNAN (no signal is raised)
20 * ilogb(inf) = INT_MAX (no signal is raised)
21 */
22
23#include <float.h>
24#include <math.h>
25
26#include "math_private.h"
27
28int
29ilogbl(long double x)
30{
31	int32_t esx,hx,lx,ix;
32
33	GET_LDOUBLE_WORDS(esx,hx,lx,x);
34	esx &= 0x7fff;
35	if(esx==0) {
36	    if((hx|lx)==0)
37		return FP_ILOGB0;	/* ilogb(0) = FP_ILOGB0 */
38	    else			/* subnormal x */
39		if(hx==0) {
40		    for (ix = -16414; lx>0; lx<<=1) ix -=1;
41		} else {
42		    for (ix = -16382; hx>0; hx<<=1) ix -=1;
43		}
44	    return ix;
45	}
46	else if (esx<0x7fff) return (esx)-16383;
47	else if ((hx&0x7fffffff|lx)!=0) return FP_ILOGBNAN;
48	else return INT_MAX;
49}
50DEF_STD(ilogbl);
51