1 /* origin: FreeBSD /usr/src/lib/msun/src/s_scalbnl.c */
3 * ====================================================
4 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
6 * Developed at SunPro, a Sun Microsystems, Inc. business.
7 * Permission to use, copy, modify, and distribute this
8 * software is freely granted, provided that this notice
10 * ====================================================
13 * scalbnl (long double x, int n)
14 * scalbnl(x,n) returns x* 2**n computed by exponent
15 * manipulation rather than by actually performing an
16 * exponentiation or a multiplication.
21 #if LDBL_MANT_DIG == 53 && LDBL_MAX_EXP == 1024
22 long double scalbnl(long double x, int n)
26 #elif (LDBL_MANT_DIG == 64 || LDBL_MANT_DIG == 113) && LDBL_MAX_EXP == 16384
27 static const long double
31 long double scalbnl(long double x, int n)
37 k = u.bits.exp; /* extract exponent */
38 if (k == 0) { /* 0 or subnormal x */
39 if ((u.bits.manh|u.bits.manl) == 0) /* +-0 */
44 return tiny*x; /*underflow*/
46 if (k == 0x7fff) /* NaN or Inf */
50 return huge*copysignl(huge, x); /* overflow */
51 if (k > 0) { /* normal result */
56 if (n > 50000) /* in case integer overflow in n+k */
57 return huge*copysign(huge, x); /*overflow*/
58 return tiny*copysign(tiny, x); /*underflow*/
59 k += 128; /* subnormal result */