1 /* s_scalbnf.c -- float version of s_scalbn.c.
2 * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com.
6 * ====================================================
7 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
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
13 * ====================================================
16 #include <sys/cdefs.h>
17 #if defined(LIBM_SCCS) && !defined(lint)
18 __RCSID("$NetBSD: s_scalbnf.c,v 1.9 2010/04/23 19:17:07 drochner Exp $");
21 #include "namespace.h"
23 #include "math_private.h"
26 __weak_alias(scalbnf
, _scalbnf
)
30 two25
= 3.355443200e+07, /* 0x4c000000 */
31 twom25
= 2.9802322388e-08, /* 0x33000000 */
36 scalbnf(float x
, int n
)
40 k
= (ix
&0x7f800000)>>23; /* extract exponent */
41 if (k
==0) { /* 0 or subnormal x */
42 if ((ix
&0x7fffffff)==0) return x
; /* +-0 */
45 k
= ((ix
&0x7f800000)>>23) - 25;
46 if (n
< -50000) return tiny
*x
; /*underflow*/
48 if (k
==0xff) return x
+x
; /* NaN or Inf */
50 if (k
> 0xfe) return huge
*copysignf(huge
,x
); /* overflow */
51 if (k
> 0) /* normal result */
52 {SET_FLOAT_WORD(x
,(ix
&0x807fffff)|(k
<<23)); return x
;}
54 if (n
> 50000) /* in case integer overflow in n+k */
55 return huge
*copysignf(huge
,x
); /*overflow*/
56 else return tiny
*copysignf(tiny
,x
); /*underflow*/
58 k
+= 25; /* subnormal result */
59 SET_FLOAT_WORD(x
,(ix
&0x807fffff)|(k
<<23));