e_scalb.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. }
  32. #if defined __UCLIBC_SUSV3_LEGACY__
  33. /*
  34. * wrapper scalb(double x, double fn) is provide for
  35. * passing various standard test suite. One
  36. * should use scalbn() instead.
  37. */
  38. #ifndef _IEEE_LIBM
  39. double scalb(double x, double fn)
  40. {
  41. double z = __ieee754_scalb(x, fn);
  42. if (_LIB_VERSION == _IEEE_)
  43. return z;
  44. if (!(isfinite(z) || isnan(z)) && isfinite(x))
  45. return __kernel_standard(x, (double)fn, 32); /* scalb overflow */
  46. if (z == 0.0 && z != x)
  47. return __kernel_standard(x, (double)fn, 33); /* scalb underflow */
  48. if (!isfinite(fn))
  49. errno = ERANGE;
  50. return z;
  51. }
  52. #else
  53. strong_alias(__ieee754_scalb, scalb)
  54. #endif
  55. #endif /* UCLIBC_SUSV3_LEGACY */