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 #include <sys/cdefs.h> 17 #if defined(LIBM_SCCS) && !defined(lint) 18 __RCSID("$NetBSD: s_scalbnf.c,v 1.12 2013/05/20 19:40:09 joerg Exp $"); 19 #endif 20 21 #include "namespace.h" 22 #include "math.h" 23 #include "math_private.h" 24 25 #ifndef _LP64 26 __strong_alias(_scalbnf, _scalblnf) 27 #endif 28 __weak_alias(scalbnf, _scalbnf) 29 __weak_alias(scalblnf, _scalblnf) 30 __weak_alias(ldexpf, _scalbnf) 31 32 static const float 33 two25 = 0x1.0p25, /* 0x4c000000 */ 34 twom25 = 0x1.0p-25, /* 0x33000000 */ 35 huge = 1.0e+30, 36 tiny = 1.0e-30; 37 38 #ifdef _LP64 39 float 40 scalbnf(float x, int n) 41 { 42 return scalblnf(x, n); 43 } 44 #endif 45 46 float 47 scalblnf(float x, long n) 48 { 49 int32_t k,ix; 50 GET_FLOAT_WORD(ix,x); 51 k = (ix&0x7f800000)>>23; /* extract exponent */ 52 if (k==0) { /* 0 or subnormal x */ 53 if ((ix&0x7fffffff)==0) return x; /* +-0 */ 54 x *= two25; 55 GET_FLOAT_WORD(ix,x); 56 k = ((ix&0x7f800000)>>23) - 25; 57 if (n< -50000) return tiny*x; /*underflow*/ 58 } 59 if (k==0xff) return x+x; /* NaN or Inf */ 60 k = k+n; 61 if (k > 0xfe) return huge*copysignf(huge,x); /* overflow */ 62 if (k > 0) /* normal result */ 63 {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;} 64 if (k <= -25) { 65 if (n > 50000) /* in case integer overflow in n+k */ 66 return huge*copysignf(huge,x); /*overflow*/ 67 else return tiny*copysignf(tiny,x); /*underflow*/ 68 } 69 k += 25; /* subnormal result */ 70 SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); 71 return x*twom25; 72 } 73