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*/
59 if (n
> OVERFLOW_INT
) /* in case integer overflow in n+k */
60 return huge
*copysignf(huge
,x
); /*overflow*/
62 if (k
> FLT_LARGEST_EXP
) return huge
*copysignf(huge
,x
); /* overflow */
63 if (k
> 0) /* normal result */
64 {SET_FLOAT_WORD(x
,(ix
&0x807fffff)|(k
<<23)); return x
;}
65 if (k
< FLT_SMALLEST_EXP
)
66 return tiny
*copysignf(tiny
,x
); /*underflow*/
67 k
+= 25; /* subnormal result */
68 SET_FLOAT_WORD(x
,(ix
&0x807fffff)|(k
<<23));
72 #ifdef _DOUBLE_IS_32BITS
75 double scalbn(double x
, int n
)
82 return (double) scalbnf((float) x
, n
);
85 #endif /* defined(_DOUBLE_IS_32BITS) */