1 /* s_frexpl.c -- long double version of s_frexp.c.
2  * Conversion to IEEE quad long double by Jakub Jelinek, jj@ultra.linux.cz.
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 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
19 
20 /*
21  * for non-zero x
22  *	x = frexpq(arg,&exp);
23  * return a long double fp quantity x such that 0.5 <= |x| <1.0
24  * and the corresponding binary exponent "exp". That is
25  *	arg = x*2^exp.
26  * If arg is inf, 0.0, or NaN, then frexpq(arg,&exp) returns arg
27  * with *exp=0.
28  */
29 
30 #include "quadmath-imp.h"
31 
32 static const __float128
33 two114 = 2.0769187434139310514121985316880384E+34Q; /* 0x4071000000000000, 0 */
34 
frexpq(__float128 x,int * eptr)35 __float128 frexpq(__float128 x, int *eptr)
36 {
37 	uint64_t hx, lx, ix;
38 	GET_FLT128_WORDS64(hx,lx,x);
39 	ix = 0x7fffffffffffffffULL&hx;
40 	*eptr = 0;
41 	if(ix>=0x7fff000000000000ULL||((ix|lx)==0)) return x + x;/* 0,inf,nan */
42 	if (ix<0x0001000000000000ULL) {		/* subnormal */
43 	    x *= two114;
44 	    GET_FLT128_MSW64(hx,x);
45 	    ix = hx&0x7fffffffffffffffULL;
46 	    *eptr = -114;
47 	}
48 	*eptr += (ix>>48)-16382;
49 	hx = (hx&0x8000ffffffffffffULL) | 0x3ffe000000000000ULL;
50 	SET_FLT128_MSW64(x,hx);
51 	return x;
52 }
53