s_scalbnf.c revision 97413
1254721Semaste/* s_scalbnf.c -- float version of s_scalbn.c.
2254721Semaste * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
3254721Semaste */
4254721Semaste
5254721Semaste/*
6254721Semaste * ====================================================
7254721Semaste * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
8254721Semaste *
9254721Semaste * Developed at SunPro, a Sun Microsystems, Inc. business.
10254721Semaste * Permission to use, copy, modify, and distribute this
11254721Semaste * software is freely granted, provided that this notice
12254721Semaste * is preserved.
13254721Semaste * ====================================================
14254721Semaste */
15254721Semaste
16254721Semaste#ifndef lint
17254721Semastestatic char rcsid[] = "$FreeBSD: head/lib/msun/src/s_scalbnf.c 97413 2002-05-28 18:15:04Z alfred $";
18254721Semaste#endif
19254721Semaste
20254721Semaste#include "math.h"
21254721Semaste#include "math_private.h"
22254721Semaste
23254721Semastestatic const float
24254721Semastetwo25   =  3.355443200e+07,	/* 0x4c000000 */
25254721Semastetwom25  =  2.9802322388e-08,	/* 0x33000000 */
26254721Semastehuge   = 1.0e+30,
27254721Semastetiny   = 1.0e-30;
28254721Semaste
29254721Semastefloat
30254721Semastescalbnf (float x, int n)
31254721Semaste{
32254721Semaste	int32_t k,ix;
33254721Semaste	GET_FLOAT_WORD(ix,x);
34254721Semaste        k = (ix&0x7f800000)>>23;		/* extract exponent */
35254721Semaste        if (k==0) {				/* 0 or subnormal x */
36254721Semaste            if ((ix&0x7fffffff)==0) return x; /* +-0 */
37254721Semaste	    x *= two25;
38254721Semaste	    GET_FLOAT_WORD(ix,x);
39254721Semaste	    k = ((ix&0x7f800000)>>23) - 25;
40254721Semaste            if (n< -50000) return tiny*x; 	/*underflow*/
41254721Semaste	    }
42254721Semaste        if (k==0xff) return x+x;		/* NaN or Inf */
43254721Semaste        k = k+n;
44254721Semaste        if (k >  0xfe) return huge*copysignf(huge,x); /* overflow  */
45254721Semaste        if (k > 0) 				/* normal result */
46254721Semaste	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
47254721Semaste        if (k <= -25)
48254721Semaste            if (n > 50000) 	/* in case integer overflow in n+k */
49254721Semaste		return huge*copysignf(huge,x);	/*overflow*/
50254721Semaste	    else return tiny*copysignf(tiny,x);	/*underflow*/
51254721Semaste        k += 25;				/* subnormal result */
52254721Semaste	SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
53254721Semaste        return x*twom25;
54254721Semaste}
55254721Semaste