e_scalb.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. /*
  41. * wrapper scalb(double x, double fn) is provide for
  42. * passing various standard test suite. One
  43. * should use scalbn() instead.
  44. */
  45. #ifndef _IEEE_LIBM
  46. # ifdef _SCALB_INT
  47. double scalb(double x, int fn)
  48. # else
  49. double scalb(double x, double fn)
  50. # endif
  51. {
  52. double z = __ieee754_scalb(x, fn);
  53. if (_LIB_VERSION == _IEEE_)
  54. return z;
  55. if (!(isfinite(z) || isnan(z)) && isfinite(x))
  56. return __kernel_standard(x, (double)fn, 32); /* scalb overflow */
  57. if (z == 0.0 && z != x)
  58. return __kernel_standard(x, (double)fn, 33); /* scalb underflow */
  59. # ifndef _SCALB_INT
  60. if (!isfinite(fn))
  61. errno = ERANGE;
  62. # endif
  63. return z;
  64. }
  65. #else
  66. strong_alias(__ieee754_scalb, scalb)
  67. #endif