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