e_scalb.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * ====================================================
  3. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  4. *
  5. * Developed at SunPro, a Sun Microsystems, Inc. business.
  6. * Permission to use, copy, modify, and distribute this
  7. * software is freely granted, provided that this notice
  8. * is preserved.
  9. * ====================================================
  10. */
  11. /*
  12. * __ieee754_scalb(x, fn) is provide for
  13. * passing various standard test suite. One
  14. * should use scalbn() instead.
  15. */
  16. #include "math.h"
  17. #include "math_private.h"
  18. #include <errno.h>
  19. double attribute_hidden __ieee754_scalb(double x, double fn)
  20. {
  21. return scalbn(x,fn);
  22. if (isnan(x)||isnan(fn)) return x*fn;
  23. if (!isfinite(fn)) {
  24. if(fn>0.0) return x*fn;
  25. else return x/(-fn);
  26. }
  27. if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
  28. if ( fn > 65000.0) return scalbn(x, 65000);
  29. if (-fn > 65000.0) return scalbn(x,-65000);
  30. return scalbn(x,(int)fn);
  31. #endif
  32. }
  33. #if defined __UCLIBC_SUSV3_LEGACY__
  34. /*
  35. * wrapper scalb(double x, double fn) is provide for
  36. * passing various standard test suite. One
  37. * should use scalbn() instead.
  38. */
  39. #ifndef _IEEE_LIBM
  40. double scalb(double x, double fn)
  41. {
  42. double z = __ieee754_scalb(x, fn);
  43. if (_LIB_VERSION == _IEEE_)
  44. return z;
  45. if (!(isfinite(z) || isnan(z)) && isfinite(x))
  46. return __kernel_standard(x, (double)fn, 32); /* scalb overflow */
  47. if (z == 0.0 && z != x)
  48. return __kernel_standard(x, (double)fn, 33); /* scalb underflow */
  49. if (!isfinite(fn))
  50. errno = ERANGE;
  51. return z;
  52. }
  53. #else
  54. strong_alias(__ieee754_scalb, scalb)
  55. #endif
  56. #endif /* UCLIBC_SUSV3_LEGACY */