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>
35 static const long double
39 two107
= 162259276829213363391578010288128.0; /* 0x4670000000000000, 0 */
42 long double __frexpl(long double x
, int *eptr
)
44 long double __frexpl(x
, eptr
)
45 long double x
; int *eptr
;
48 u_int64_t hx
, lx
, ix
, ixl
;
50 GET_LDOUBLE_WORDS64(hx
,lx
,x
);
51 ixl
= 0x7fffffffffffffffULL
&lx
;
52 ix
= 0x7fffffffffffffffULL
&hx
;
54 if(ix
>=0x7ff0000000000000ULL
||((ix
|ixl
)==0)) return x
; /* 0,inf,nan */
55 if (ix
<0x0010000000000000ULL
) { /* subnormal */
57 GET_LDOUBLE_MSW64(hx
,x
);
58 ix
= hx
&0x7fffffffffffffffULL
;
61 *eptr
+= (ix
>>52)-1022;
64 explo
= (ixl
>>52) - (ix
>>52) + 0x3fe;
65 if ((ixl
&0x7ff0000000000000ULL
) == 0LL) {
66 /* the lower double is a denomal so we need to correct its
67 mantissa and perhaps its exponent. */
70 if (sizeof (ixl
) == sizeof (long))
71 cnt
= __builtin_clzl (ixl
);
72 else if ((ixl
>> 32) != 0)
73 cnt
= __builtin_clzl ((long) (ixl
>> 32));
75 cnt
= __builtin_clzl ((long) ixl
) + 32;
77 lx
= (lx
&0x8000000000000000ULL
) | ((explo
-cnt
)<<52)
78 | ((ixl
<<(cnt
+1))&0x000fffffffffffffULL
);
80 lx
= (lx
&0x800fffffffffffffULL
) | (explo
<<52);
84 hx
= (hx
&0x800fffffffffffffULL
) | 0x3fe0000000000000ULL
;
85 SET_LDOUBLE_WORDS64(x
,hx
,lx
);
89 long_double_symbol (libm
, __frexpl
, frexpl
);
91 long_double_symbol (libc
, __frexpl
, frexpl
);