Blame sysdeps/ieee754/flt-32/s_scalbnf.c

Packit 6c4009
/* s_scalbnf.c -- float version of s_scalbn.c.
Packit 6c4009
 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
/*
Packit 6c4009
 * ====================================================
Packit 6c4009
 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
Packit 6c4009
 *
Packit 6c4009
 * Developed at SunPro, a Sun Microsystems, Inc. business.
Packit 6c4009
 * Permission to use, copy, modify, and distribute this
Packit 6c4009
 * software is freely granted, provided that this notice
Packit 6c4009
 * is preserved.
Packit 6c4009
 * ====================================================
Packit 6c4009
 */
Packit 6c4009
Packit 6c4009
#include <math.h>
Packit 6c4009
#include <math_private.h>
Packit 6c4009
Packit 6c4009
static const float
Packit 6c4009
two25   =  3.355443200e+07,	/* 0x4c000000 */
Packit 6c4009
twom25  =  2.9802322388e-08,	/* 0x33000000 */
Packit 6c4009
huge   = 1.0e+30,
Packit 6c4009
tiny   = 1.0e-30;
Packit 6c4009
Packit 6c4009
float
Packit 6c4009
__scalbnf (float x, int n)
Packit 6c4009
{
Packit 6c4009
	int32_t k,ix;
Packit 6c4009
	GET_FLOAT_WORD(ix,x);
Packit 6c4009
	k = (ix&0x7f800000)>>23;		/* extract exponent */
Packit 6c4009
	if (__builtin_expect(k==0, 0)) {	/* 0 or subnormal x */
Packit 6c4009
	    if ((ix&0x7fffffff)==0) return x; /* +-0 */
Packit 6c4009
	    x *= two25;
Packit 6c4009
	    GET_FLOAT_WORD(ix,x);
Packit 6c4009
	    k = ((ix&0x7f800000)>>23) - 25;
Packit 6c4009
	    }
Packit 6c4009
	if (__builtin_expect(k==0xff, 0)) return x+x;	/* NaN or Inf */
Packit 6c4009
	if (__builtin_expect(n< -50000, 0))
Packit 6c4009
	  return tiny*__copysignf(tiny,x);	/*underflow*/
Packit 6c4009
	if (__builtin_expect(n> 50000 || k+n > 0xfe, 0))
Packit 6c4009
	  return huge*__copysignf(huge,x); /* overflow  */
Packit 6c4009
	/* Now k and n are bounded we know that k = k+n does not
Packit 6c4009
	   overflow.  */
Packit 6c4009
	k = k+n;
Packit 6c4009
	if (__builtin_expect(k > 0, 1))		/* normal result */
Packit 6c4009
	    {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
Packit 6c4009
	if (k <= -25)
Packit 6c4009
	    return tiny*__copysignf(tiny,x);	/*underflow*/
Packit 6c4009
	k += 25;				/* subnormal result */
Packit 6c4009
	SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
Packit 6c4009
	return x*twom25;
Packit 6c4009
}