w_scalb.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* Copyright (C) 2011-2016 Free Software Foundation, Inc.
  2. This file is part of the GNU C Library.
  3. Contributed by Ulrich Drepper <drepper@gmail.com>, 2011.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #include <math.h>
  16. #include "math_private.h"
  17. #if defined(__UCLIBC_HAS_FENV__)
  18. #include <errno.h>
  19. static double
  20. __attribute__ ((noinline))
  21. sysv_scalb (double x, double fn)
  22. {
  23. double z = __ieee754_scalb (x, fn);
  24. if (__builtin_expect (isinf (z), 0))
  25. {
  26. if (isfinite (x))
  27. return __kernel_standard (x, fn, 32); /* scalb overflow */
  28. else
  29. __set_errno (ERANGE);
  30. }
  31. else if (__builtin_expect (z == 0.0, 0) && z != x)
  32. return __kernel_standard (x, fn, 33); /* scalb underflow */
  33. return z;
  34. }
  35. #endif /* __UCLIBC_HAS_FENV__ */
  36. /* Here might be a check like "#if defined __UCLIBC_SUSV3_LEGACY__"
  37. * but because there is a sysv_scalb() func, it was decided
  38. * not to check yhis macro.
  39. */
  40. /* Wrapper scalb */
  41. double
  42. scalb (double x, double fn)
  43. {
  44. #if defined(__UCLIBC_HAS_FENV__)
  45. if (__builtin_expect (_LIB_VERSION == _SVID_,0))
  46. return sysv_scalb (x, fn);
  47. else
  48. {
  49. double z = __ieee754_scalb (x, fn);
  50. if (__builtin_expect (!isfinite (z) || z == 0.0, 0))
  51. {
  52. if (isnan (z))
  53. {
  54. if (!isnan (x) && !isnan (fn))
  55. __set_errno (EDOM);
  56. }
  57. else if (isinf (z))
  58. {
  59. if (!isinf (x) && !isinf (fn))
  60. __set_errno (ERANGE);
  61. }
  62. else
  63. {
  64. /* z == 0. */
  65. if (x != 0.0 && !isinf (fn))
  66. __set_errno (ERANGE);
  67. }
  68. }
  69. return z;
  70. }
  71. #else
  72. return __ieee754_scalb (x, fn);
  73. #endif /* __UCLIBC_HAS_FENV__ */
  74. }
  75. libm_hidden_def(scalb)