Add support for ARMv8-R architecture
[official-gcc.git] / libquadmath / math / scalblnq.c
bloba414045b51f84fb61aa0c49bfc5a59f96a3ec246
1 /* scalblnq.c -- __float128 version of s_scalbn.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 * ====================================================
17 * scalblnq (_float128 x, long int n)
18 * scalblnq(x,n) returns x* 2**n computed by exponent
19 * manipulation rather than by actually performing an
20 * exponentiation or a multiplication.
23 #include "quadmath-imp.h"
25 static const __float128
26 two114 = 2.0769187434139310514121985316880384E+34Q, /* 0x4071000000000000, 0 */
27 twom114 = 4.8148248609680896326399448564623183E-35Q, /* 0x3F8D000000000000, 0 */
28 huge = 1.0E+4900Q,
29 tiny = 1.0E-4900Q;
31 __float128
32 scalblnq (__float128 x, long int n)
34 int64_t k,hx,lx;
35 GET_FLT128_WORDS64(hx,lx,x);
36 k = (hx>>48)&0x7fff; /* extract exponent */
37 if (k==0) { /* 0 or subnormal x */
38 if ((lx|(hx&0x7fffffffffffffffULL))==0) return x; /* +-0 */
39 x *= two114;
40 GET_FLT128_MSW64(hx,x);
41 k = ((hx>>48)&0x7fff) - 114;
43 if (k==0x7fff) return x+x; /* NaN or Inf */
44 if (n< -50000) return tiny*copysignq(tiny,x); /*underflow*/
45 if (n> 50000 || k+n > 0x7ffe)
46 return huge*copysignq(huge,x); /* overflow */
47 /* Now k and n are bounded we know that k = k+n does not
48 overflow. */
49 k = k+n;
50 if (k > 0) /* normal result */
51 {SET_FLT128_MSW64(x,(hx&0x8000ffffffffffffULL)|(k<<48)); return x;}
52 if (k <= -114)
53 return tiny*copysignq(tiny,x); /*underflow*/
54 k += 114; /* subnormal result */
55 SET_FLT128_MSW64(x,(hx&0x8000ffffffffffffULL)|(k<<48));
56 return x*twom114;