w_scalb.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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_SUSV3_LEGACY__
  18. #if defined(__UCLIBC_HAS_FENV__)
  19. #include <errno.h>
  20. static double
  21. __attribute__ ((noinline))
  22. sysv_scalb (double x, double fn)
  23. {
  24. double z = __ieee754_scalb (x, fn);
  25. if (__builtin_expect (isinf (z), 0))
  26. {
  27. if (isfinite (x))
  28. return __kernel_standard (x, fn, 32); /* scalb overflow */
  29. else
  30. __set_errno (ERANGE);
  31. }
  32. else if (__builtin_expect (z == 0.0, 0) && z != x)
  33. return __kernel_standard (x, fn, 33); /* scalb underflow */
  34. return z;
  35. }
  36. #endif /* __UCLIBC_HAS_FENV__ */
  37. /* Wrapper scalb */
  38. double
  39. scalb (double x, double fn)
  40. {
  41. #if defined(__UCLIBC_HAS_FENV__)
  42. if (__builtin_expect (_LIB_VERSION == _SVID_,0))
  43. return sysv_scalb (x, fn);
  44. else
  45. {
  46. double z = __ieee754_scalb (x, fn);
  47. if (__builtin_expect (!isfinite (z) || z == 0.0, 0))
  48. {
  49. if (isnan (z))
  50. {
  51. if (!isnan (x) && !isnan (fn))
  52. __set_errno (EDOM);
  53. }
  54. else if (isinf (z))
  55. {
  56. if (!isinf (x) && !isinf (fn))
  57. __set_errno (ERANGE);
  58. }
  59. else
  60. {
  61. /* z == 0. */
  62. if (x != 0.0 && !isinf (fn))
  63. __set_errno (ERANGE);
  64. }
  65. }
  66. return z;
  67. }
  68. #else
  69. return __ieee754_scalb (x, fn);
  70. #endif /* __UCLIBC_HAS_FENV__ */
  71. }
  72. libm_hidden_def(scalb)
  73. #endif