e_scalb.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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 provided for
  13. * passing various standard test suites.
  14. * One 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. if (isnan(x)||isnan(fn)) return x*fn;
  22. if (!isfinite(fn)) {
  23. if(fn>0.0) return x*fn;
  24. else return x/(-fn);
  25. }
  26. if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
  27. if ( fn > 65000.0) return scalbn(x, 65000);
  28. if (-fn > 65000.0) return scalbn(x,-65000);
  29. return scalbn(x,(int)fn);
  30. }
  31. #if defined __UCLIBC_SUSV3_LEGACY__
  32. /*
  33. * wrapper scalb(double x, double fn) is provided for
  34. * passing various standard test suites.
  35. * One should use scalbn() instead.
  36. */
  37. #ifndef _IEEE_LIBM
  38. double scalb(double x, double fn)
  39. {
  40. double z = __ieee754_scalb(x, fn);
  41. if (_LIB_VERSION == _IEEE_)
  42. return z;
  43. if (!(isfinite(z) || isnan(z)) && isfinite(x))
  44. return __kernel_standard(x, (double)fn, 32); /* scalb overflow */
  45. if (z == 0.0 && z != x)
  46. return __kernel_standard(x, (double)fn, 33); /* scalb underflow */
  47. if (!isfinite(fn))
  48. errno = ERANGE;
  49. return z;
  50. }
  51. #else
  52. strong_alias(__ieee754_scalb, scalb)
  53. #endif
  54. #endif /* UCLIBC_SUSV3_LEGACY */