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.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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
13 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid
[] = "$NetBSD: $";
22 * x = frexpl(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
26 * If arg is inf, 0.0, or NaN, then frexpl(arg,&exp) returns arg
31 #include <math_private.h>
32 #include <math_ldbl_opt.h>
34 static const long double
35 two107
= 162259276829213363391578010288128.0; /* 0x4670000000000000, 0 */
37 long double __frexpl(long double x
, int *eptr
)
39 u_int64_t hx
, lx
, ix
, ixl
;
41 GET_LDOUBLE_WORDS64(hx
,lx
,x
);
42 ixl
= 0x7fffffffffffffffULL
&lx
;
43 ix
= 0x7fffffffffffffffULL
&hx
;
45 if(ix
>=0x7ff0000000000000ULL
||((ix
|ixl
)==0)) return x
; /* 0,inf,nan */
46 if (ix
<0x0010000000000000ULL
) { /* subnormal */
48 GET_LDOUBLE_MSW64(hx
,x
);
49 ix
= hx
&0x7fffffffffffffffULL
;
52 *eptr
+= (ix
>>52)-1022;
55 explo
= (ixl
>>52) - (ix
>>52) + 0x3fe;
56 if ((ixl
&0x7ff0000000000000ULL
) == 0LL) {
57 /* the lower double is a denomal so we need to correct its
58 mantissa and perhaps its exponent. */
61 if (sizeof (ixl
) == sizeof (long))
62 cnt
= __builtin_clzl (ixl
);
63 else if ((ixl
>> 32) != 0)
64 cnt
= __builtin_clzl ((long) (ixl
>> 32));
66 cnt
= __builtin_clzl ((long) ixl
) + 32;
68 lx
= (lx
&0x8000000000000000ULL
) | ((explo
-cnt
)<<52)
69 | ((ixl
<<(cnt
+1))&0x000fffffffffffffULL
);
71 lx
= (lx
&0x800fffffffffffffULL
) | (explo
<<52);
75 hx
= (hx
&0x800fffffffffffffULL
) | 0x3fe0000000000000ULL
;
76 SET_LDOUBLE_WORDS64(x
,hx
,lx
);
80 long_double_symbol (libm
, __frexpl
, frexpl
);
82 long_double_symbol (libc
, __frexpl
, frexpl
);