1 /* sf_scalbn.c -- float version of s_scalbn.c.
2  * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3  */
4 
5 /*
6  * ====================================================
7  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8  *
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
12  * is preserved.
13  * ====================================================
14  */
15 
16 #include "fdlibm.h"
17 #include <limits.h>
18 #include <float.h>
19 
20 #if INT_MAX > 50000
21 #define OVERFLOW_INT 50000
22 #else
23 #define OVERFLOW_INT 30000
24 #endif
25 
26 static const float
27 two25   =  3.355443200e+07,	/* 0x4c000000 */
28 twom25  =  2.9802322388e-08;	/* 0x33000000 */
29 
scalbnf(float x,int n)30 float scalbnf (float x, int n)
31 {
32 	__int32_t  k,ix;
33 	__uint32_t hx;
34 
35 	GET_FLOAT_WORD(ix,x);
36 	hx = ix&0x7fffffff;
37         k = hx>>23;		/* extract exponent */
38         if (k == 0) {
39             if (hx == 0) return x;
40 	    x *= two25;
41 	    GET_FLOAT_WORD(ix,x);
42 	    k = ((ix&0x7f800000)>>23) - 25;
43 #if __SIZEOF_INT__ > 2
44             if (n< -50000)
45                 return __math_uflowf(ix<0); 	/*underflow*/
46 #endif
47         }
48         if (k == 0xff)  return x + x;	/* NaN or Inf */
49         if (n > OVERFLOW_INT) 	/* in case integer overflow in n+k */
50             return __math_oflowf(ix<0);	        /*overflow*/
51         k = k+n;
52         if (k > FLT_LARGEST_EXP)
53             return __math_oflowf(ix<0);          /* overflow  */
54         if (k > 0) 				/* normal result */
55 	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
56         if (k < -25)
57 	    return __math_uflowf(ix<0);	        /*underflow*/
58         k += 25;				/* subnormal result */
59 	SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
60         return check_uflowf(x*twom25);
61 }
62 
63 #if defined(_HAVE_ALIAS_ATTRIBUTE)
64 #ifndef __clang__
65 #pragma GCC diagnostic ignored "-Wmissing-attributes"
66 #endif
67 __strong_reference(scalbnf, ldexpf);
68 #else
69 
70 float
ldexpf(float value,int exp)71 ldexpf(float value, int exp)
72 {
73     return scalbnf(value, exp);
74 }
75 
76 #endif
77 
78 _MATH_ALIAS_f_fi(scalbn)
79 _MATH_ALIAS_f_fi(ldexp)
80