1 /* s_scalbnf.c -- float version of s_scalbn.c.
2  */
3 
4 /*
5  * ====================================================
6  * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
7  *
8  * Developed at SunPro, a Sun Microsystems, Inc. business.
9  * Permission to use, copy, modify, and distribute this
10  * software is freely granted, provided that this notice
11  * is preserved.
12  * ====================================================
13  */
14 
15 #include <math.h>
16 #include <math_private.h>
17 
18 static const float
19 two25   =  3.355443200e+07,	/* 0x4c000000 */
20 twom25  =  2.9802322388e-08,	/* 0x33000000 */
21 huge   = 1.0e+30,
22 tiny   = 1.0e-30;
23 
24 float
__scalblnf(float x,long int n)25 __scalblnf (float x, long int n)
26 {
27 	int32_t k,ix;
28 	GET_FLOAT_WORD(ix,x);
29 	k = (ix&0x7f800000)>>23;		/* extract exponent */
30 	if (__builtin_expect(k==0, 0)) {	/* 0 or subnormal x */
31 	    if ((ix&0x7fffffff)==0) return x; /* +-0 */
32 	    x *= two25;
33 	    GET_FLOAT_WORD(ix,x);
34 	    k = ((ix&0x7f800000)>>23) - 25;
35 	    }
36 	if (__builtin_expect(k==0xff, 0)) return x+x;	/* NaN or Inf */
37 	if (__builtin_expect(n< -50000, 0))
38 	  return tiny*copysignf(tiny,x);	/*underflow*/
39 	if (__builtin_expect(n> 50000 || k+n > 0xfe, 0))
40 	  return huge*copysignf(huge,x); /* overflow  */
41 	/* Now k and n are bounded we know that k = k+n does not
42 	   overflow.  */
43 	k = k+n;
44 	if (__builtin_expect(k > 0, 1))		/* normal result */
45 	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
46 	if (k <= -25)
47 	    return tiny*copysignf(tiny,x);	/*underflow*/
48 	k += 25;				/* subnormal result */
49 	SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
50 	return x*twom25;
51 }
52