w_scalbl_compat.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright (C) 2011-2019 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 <errno.h>
  16. #include <math.h>
  17. #include <math_private.h>
  18. #include <math-svid-compat.h>
  19. #if LIBM_SVID_COMPAT
  20. static long double
  21. __attribute__ ((noinline))
  22. sysv_scalbl (long double x, long double fn)
  23. {
  24. long double z = __ieee754_scalbl (x, fn);
  25. if (__glibc_unlikely (isinf (z)))
  26. {
  27. if (isfinite (x))
  28. return __kernel_standard_l (x, fn, 232); /* scalb overflow */
  29. else
  30. __set_errno (ERANGE);
  31. }
  32. else if (__builtin_expect (z == 0.0L, 0) && z != x)
  33. return __kernel_standard_l (x, fn, 233); /* scalb underflow */
  34. return z;
  35. }
  36. #endif
  37. /* Wrapper scalbl */
  38. long double
  39. __scalbl (long double x, long double fn)
  40. {
  41. #if LIBM_SVID_COMPAT
  42. if (__glibc_unlikely (_LIB_VERSION == _SVID_))
  43. return sysv_scalbl (x, fn);
  44. else
  45. #endif
  46. {
  47. long double z = __ieee754_scalbl (x, fn);
  48. if (__glibc_unlikely (!isfinite (z) || z == 0.0L))
  49. {
  50. if (isnan (z))
  51. {
  52. if (!isnan (x) && !isnan (fn))
  53. __set_errno (EDOM);
  54. }
  55. else if (isinf (z))
  56. {
  57. if (!isinf (x) && !isinf (fn))
  58. __set_errno (ERANGE);
  59. }
  60. else
  61. {
  62. /* z == 0. */
  63. if (x != 0.0L && !isinf (fn))
  64. __set_errno (ERANGE);
  65. }
  66. }
  67. return z;
  68. }
  69. }
  70. weak_alias (__scalbl, scalbl)