e_scalb.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifdef _SCALB_INT
  20. double attribute_hidden __ieee754_scalb(double x, int fn)
  21. #else
  22. double attribute_hidden __ieee754_scalb(double x, double fn)
  23. #endif
  24. {
  25. #ifdef _SCALB_INT
  26. return scalbn(x,fn);
  27. //TODO: just alias it to scalbn?
  28. #else
  29. if (isnan(x)||isnan(fn)) return x*fn;
  30. if (!isfinite(fn)) {
  31. if(fn>0.0) return x*fn;
  32. else return x/(-fn);
  33. }
  34. if (rint(fn)!=fn) return (fn-fn)/(fn-fn);
  35. if ( fn > 65000.0) return scalbn(x, 65000);
  36. if (-fn > 65000.0) return scalbn(x,-65000);
  37. return scalbn(x,(int)fn);
  38. #endif
  39. }
  40. #if defined __UCLIBC_SUSV3_LEGACY__
  41. /*
  42. * wrapper scalb(double x, double fn) is provide for
  43. * passing various standard test suite. One
  44. * should use scalbn() instead.
  45. */
  46. #ifndef _IEEE_LIBM
  47. # ifdef _SCALB_INT
  48. double scalb(double x, int fn)
  49. # else
  50. double scalb(double x, double fn)
  51. # endif
  52. {
  53. double z = __ieee754_scalb(x, fn);
  54. if (_LIB_VERSION == _IEEE_)
  55. return z;
  56. if (!(isfinite(z) || isnan(z)) && isfinite(x))
  57. return __kernel_standard(x, (double)fn, 32); /* scalb overflow */
  58. if (z == 0.0 && z != x)
  59. return __kernel_standard(x, (double)fn, 33); /* scalb underflow */
  60. # ifndef _SCALB_INT
  61. if (!isfinite(fn))
  62. errno = ERANGE;
  63. # endif
  64. return z;
  65. }
  66. #else
  67. strong_alias(__ieee754_scalb, scalb)
  68. #endif
  69. #endif /* UCLIBC_SUSV3_LEGACY */