PowerPC floating point little-endian [2 of 15]
[glibc.git] / sysdeps / ieee754 / ldbl-128ibm / s_frexpl.c
blob3ac537411603757149db4ea41b42b1a906d22b9f
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 */
5 /*
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
12 * is preserved.
13 * ====================================================
16 #if defined(LIBM_SCCS) && !defined(lint)
17 static char rcsid[] = "$NetBSD: $";
18 #endif
21 * for non-zero x
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
25 * arg = x*2^exp.
26 * If arg is inf, 0.0, or NaN, then frexpl(arg,&exp) returns arg
27 * with *exp=0.
30 #include <math.h>
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;
40 int64_t explo;
41 GET_LDOUBLE_WORDS64(hx,lx,x);
42 ixl = 0x7fffffffffffffffULL&lx;
43 ix = 0x7fffffffffffffffULL&hx;
44 *eptr = 0;
45 if(ix>=0x7ff0000000000000ULL||((ix|ixl)==0)) return x; /* 0,inf,nan */
46 if (ix<0x0010000000000000ULL) { /* subnormal */
47 x *= two107;
48 GET_LDOUBLE_MSW64(hx,x);
49 ix = hx&0x7fffffffffffffffULL;
50 *eptr = -107;
52 *eptr += (ix>>52)-1022;
54 if (ixl != 0ULL) {
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. */
59 int cnt;
61 if (sizeof (ixl) == sizeof (long))
62 cnt = __builtin_clzl (ixl);
63 else if ((ixl >> 32) != 0)
64 cnt = __builtin_clzl ((long) (ixl >> 32));
65 else
66 cnt = __builtin_clzl ((long) ixl) + 32;
67 cnt = cnt - 12;
68 lx = (lx&0x8000000000000000ULL) | ((explo-cnt)<<52)
69 | ((ixl<<(cnt+1))&0x000fffffffffffffULL);
70 } else
71 lx = (lx&0x800fffffffffffffULL) | (explo<<52);
72 } else
73 lx = 0ULL;
75 hx = (hx&0x800fffffffffffffULL) | 0x3fe0000000000000ULL;
76 SET_LDOUBLE_WORDS64(x,hx,lx);
77 return x;
79 #ifdef IS_IN_libm
80 long_double_symbol (libm, __frexpl, frexpl);
81 #else
82 long_double_symbol (libc, __frexpl, frexpl);
83 #endif