1 /* s_frexpl.c -- long double version of s_frexp.c.
2  */
3 
4 /*
5  * ====================================================
6  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7  *
8  * Developed at SunPro, a Sun Microsystems, Inc. business.
9  * Permission to use, copy, modify, and distribute this
10  * software is freely granted, provided that this notice
11  * is preserved.
12  * ====================================================
13  */
14 
15 #if defined(LIBM_SCCS) && !defined(lint)
16 static char rcsid[] = "$NetBSD: $";
17 #endif
18 
19 /*
20  * for non-zero x
21  *	x = frexpl(arg,&exp);
22  * return a long double fp quantity x such that 0.5 <= |x| <1.0
23  * and the corresponding binary exponent "exp". That is
24  *	arg = x*2^exp.
25  * If arg is inf, 0.0, or NaN, then frexpl(arg,&exp) returns arg
26  * with *exp=0.
27  */
28 
29 #include <math.h>
30 #include <math_private.h>
31 #include <libm-alias-ldouble.h>
32 
33 static const _Float128
34 two114 = L(2.0769187434139310514121985316880384E+34); /* 0x4071000000000000, 0 */
35 
__frexpl(_Float128 x,int * eptr)36 _Float128 __frexpl(_Float128 x, int *eptr)
37 {
38 	uint64_t hx, lx, ix;
39 	GET_LDOUBLE_WORDS64(hx,lx,x);
40 	ix = 0x7fffffffffffffffULL&hx;
41 	*eptr = 0;
42 	if(ix>=0x7fff000000000000ULL||((ix|lx)==0)) return x + x;/* 0,inf,nan */
43 	if (ix<0x0001000000000000ULL) {		/* subnormal */
44 	    x *= two114;
45 	    GET_LDOUBLE_MSW64(hx,x);
46 	    ix = hx&0x7fffffffffffffffULL;
47 	    *eptr = -114;
48 	}
49 	*eptr += (ix>>48)-16382;
50 	hx = (hx&0x8000ffffffffffffULL) | 0x3ffe000000000000ULL;
51 	SET_LDOUBLE_MSW64(x,hx);
52 	return x;
53 }
54 libm_alias_ldouble (__frexp, frexp)
55