s_scalbnf.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  7. *
  8. * Developed at SunPro, a Sun Microsystems, Inc. business.
  9. * Permission to use, copy, modify, and distribute this
  10. * software is freely granted, provided that this notice
  11. * is preserved.
  12. * ====================================================
  13. */
  14. #include "cdefs-compat.h"
  15. #include <openlibm_math.h>
  16. #include "math_private.h"
  17. static const float
  18. two25 = 3.355443200e+07, /* 0x4c000000 */
  19. twom25 = 2.9802322388e-08, /* 0x33000000 */
  20. huge = 1.0e+30,
  21. tiny = 1.0e-30;
  22. DLLEXPORT float
  23. scalbnf (float x, int n)
  24. {
  25. int32_t k,ix;
  26. GET_FLOAT_WORD(ix,x);
  27. k = (ix&0x7f800000)>>23; /* extract exponent */
  28. if (k==0) { /* 0 or subnormal x */
  29. if ((ix&0x7fffffff)==0) return x; /* +-0 */
  30. x *= two25;
  31. GET_FLOAT_WORD(ix,x);
  32. k = ((ix&0x7f800000)>>23) - 25;
  33. if (n< -50000) return tiny*x; /*underflow*/
  34. }
  35. if (k==0xff) return x+x; /* NaN or Inf */
  36. k = k+n;
  37. if (k > 0xfe) return huge*copysignf(huge,x); /* overflow */
  38. if (k > 0) /* normal result */
  39. {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;}
  40. if (k <= -25) {
  41. if (n > 50000) /* in case integer overflow in n+k */
  42. return huge*copysignf(huge,x); /*overflow*/
  43. else return tiny*copysignf(tiny,x); /*underflow*/
  44. }
  45. k += 25; /* subnormal result */
  46. SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23));
  47. return x*twom25;
  48. }
  49. __strong_reference(scalbnf, ldexpf);