1 /* $OpenBSD: s_scalbnl.c,v 1.3 2013/11/12 18:28:02 martynas Exp $ */
2 /* @(#)s_scalbn.c 5.1 93/09/24 */
4 * ====================================================
5 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7 * Developed at SunPro, a Sun Microsystems, Inc. business.
8 * Permission to use, copy, modify, and distribute this
9 * software is freely granted, provided that this notice
11 * ====================================================
15 * scalbnl (long double x, int n)
16 * scalbnl(x,n) returns x* 2**n computed by exponent
17 * manipulation rather than by actually performing an
18 * exponentiation or a multiplication.
22 * We assume that a long double has a 15-bit exponent. On systems
23 * where long double is the same as double, scalbnl() is an alias
24 * for scalbn(), so we don't use this routine.
27 #include <sys/types.h>
28 #include <machine/ieee.h>
32 #if LDBL_MAX_EXP != 0x4000
33 #error "Unsupported long double format"
36 static const long double
41 scalbnl (long double x, int n)
49 k = u.bits.ext_exp; /* extract exponent */
50 if (k==0) { /* 0 or subnormal x */
54 #endif /* EXT_FRACHMBITS */
57 #endif /* EXT_FRACLMBITS */
58 | u.bits.ext_fracl)==0) return x; /* +-0 */
60 k = u.bits.ext_exp - 128;
61 if (n< -50000) return tiny*x; /*underflow*/
63 if (k==0x7fff) return x+x; /* NaN or Inf */
65 if (k >= 0x7fff) return huge*copysignl(huge,x); /* overflow */
66 if (k > 0) /* normal result */
67 {u.bits.ext_exp = k; return u.e;}
69 if (n > 50000) /* in case integer overflow in n+k */
70 return huge*copysign(huge,x); /*overflow*/
71 else return tiny*copysign(tiny,x); /*underflow*/
73 k += 128; /* subnormal result */
79 ldexpl(long double x, int n)