1 /* sf_scalbn.c -- float version of s_scalbn.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
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
13 * ====================================================
21 #define OVERFLOW_INT 50000
23 #define OVERFLOW_INT 30000
31 two25 = 3.355443200e+07, /* 0x4c000000 */
32 twom25 = 2.9802322388e-08, /* 0x33000000 */
37 float scalbnf (float x, int n)
48 k = hx>>23; /* extract exponent */
49 if (FLT_UWORD_IS_ZERO(hx))
51 if (!FLT_UWORD_IS_FINITE(hx))
52 return x+x; /* NaN or Inf */
53 if (FLT_UWORD_IS_SUBNORMAL(hx)) {
56 k = ((ix&0x7f800000)>>23) - 25;
57 if (n< -50000) return tiny*x; /*underflow*/
60 if (k > FLT_LARGEST_EXP) return huge*copysignf(huge,x); /* overflow */
61 if (k > 0) /* normal result */
62 {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
63 if (k < FLT_SMALLEST_EXP) {
64 if (n > OVERFLOW_INT) /* in case integer overflow in n+k */
65 return huge*copysignf(huge,x); /*overflow*/
66 else return tiny*copysignf(tiny,x); /*underflow*/
68 k += 25; /* subnormal result */
69 SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
73 #ifdef _DOUBLE_IS_32BITS
76 double scalbn(double x, int n)
83 return (double) scalbnf((float) x, n);
86 #endif /* defined(_DOUBLE_IS_32BITS) */