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