1 /* @(#)s_scalbn.c 5.1 93/09/24 */
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 * ====================================================
14 static char rcsid
[] = "$FreeBSD: src/lib/msun/src/s_scalbnl.c,v 1.1 2005/03/07 04:52:58 das Exp $";
18 * scalbnl (long double x, int n)
19 * scalbnl(x,n) returns x* 2**n computed by exponent
20 * manipulation rather than by actually performing an
21 * exponentiation or a multiplication.
25 * We assume that a long double has a 15-bit exponent. On systems
26 * where long double is the same as double, scalbnl() is an alias
27 * for scalbn(), so we don't use this routine.
30 #include <sys/cdefs.h>
36 #if LDBL_MAX_EXP != 0x4000
37 #error "Unsupported long double format"
40 static const long double
45 scalbnl (long double x
, int n
)
50 k
= u
.bits
.exp
; /* extract exponent */
51 if (k
==0) { /* 0 or subnormal x */
52 if ((u
.bits
.manh
|u
.bits
.manl
)==0) return x
; /* +-0 */
55 if (n
< -50000) return tiny
*x
; /*underflow*/
57 if (k
==0x7fff) return x
+x
; /* NaN or Inf */
59 if (k
>= 0x7fff) return huge
*copysignl(huge
,x
); /* overflow */
60 if (k
> 0) /* normal result */
61 {u
.bits
.exp
= k
; return u
.e
;}
63 if (n
> 50000) /* in case integer overflow in n+k */
64 return huge
*copysign(huge
,x
); /*overflow*/
65 else return tiny
*copysign(tiny
,x
); /*underflow*/
66 k
+= 128; /* subnormal result */
71 __strong_reference(scalbnl
, ldexpl
);