xref: /relibc/openlibm/src/s_scalbnf.c (revision 28fb939b0de8e3c8a7fd6064a7277410b84b292f)
1 /* s_scalbnf.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 
17 #include "cdefs-compat.h"
18 
19 #include <openlibm_math.h>
20 
21 #include "math_private.h"
22 
23 static const float
24 two25   =  3.355443200e+07,	/* 0x4c000000 */
25 twom25  =  2.9802322388e-08,	/* 0x33000000 */
26 huge   = 1.0e+30,
27 tiny   = 1.0e-30;
28 
29 OLM_DLLEXPORT float
30 scalbnf (float x, int n)
31 {
32 	int32_t k,ix;
33 	GET_FLOAT_WORD(ix,x);
34         k = (ix&0x7f800000)>>23;		/* extract exponent */
35         if (k==0) {				/* 0 or subnormal x */
36             if ((ix&0x7fffffff)==0) return x; /* +-0 */
37 	    x *= two25;
38 	    GET_FLOAT_WORD(ix,x);
39 	    k = ((ix&0x7f800000)>>23) - 25;
40             if (n< -50000) return tiny*x; 	/*underflow*/
41 	    }
42         if (k==0xff) return x+x;		/* NaN or Inf */
43         k = k+n;
44         if (k >  0xfe) return huge*copysignf(huge,x); /* overflow  */
45         if (k > 0) 				/* normal result */
46 	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
47         if (k <= -25) {
48             if (n > 50000) 	/* in case integer overflow in n+k */
49 		return huge*copysignf(huge,x);	/*overflow*/
50 	    else return tiny*copysignf(tiny,x);	/*underflow*/
51         }
52 	k += 25;				/* subnormal result */
53 	SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
54         return x*twom25;
55 }
56 
57 __strong_reference(scalbnf, ldexpf);
58