w_pow_compat.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 <math.h>
  16. #include <math_private.h>
  17. #include <math-svid-compat.h>
  18. #include <libm-alias-double.h>
  19. #if LIBM_SVID_COMPAT && (SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_29) \
  20. || defined NO_LONG_DOUBLE \
  21. || defined LONG_DOUBLE_COMPAT)
  22. /* wrapper pow */
  23. double
  24. __pow_compat (double x, double y)
  25. {
  26. double z = __ieee754_pow (x, y);
  27. if (__glibc_unlikely (!isfinite (z)))
  28. {
  29. if (_LIB_VERSION != _IEEE_)
  30. {
  31. if (isfinite (x) && isfinite (y))
  32. {
  33. if (isnan (z))
  34. /* pow neg**non-int */
  35. return __kernel_standard (x, y, 24);
  36. else if (x == 0.0 && y < 0.0)
  37. {
  38. if (signbit (x) && signbit (z))
  39. /* pow(-0.0,negative) */
  40. return __kernel_standard (x, y, 23);
  41. else
  42. /* pow(+0.0,negative) */
  43. return __kernel_standard (x, y, 43);
  44. }
  45. else
  46. /* pow overflow */
  47. return __kernel_standard (x, y, 21);
  48. }
  49. }
  50. }
  51. else if (__builtin_expect (z == 0.0, 0)
  52. && isfinite (x) && x != 0 && isfinite (y)
  53. && _LIB_VERSION != _IEEE_)
  54. /* pow underflow */
  55. return __kernel_standard (x, y, 22);
  56. return z;
  57. }
  58. # if SHLIB_COMPAT (libm, GLIBC_2_0, GLIBC_2_29)
  59. compat_symbol (libm, __pow_compat, pow, GLIBC_2_0);
  60. # endif
  61. # ifdef NO_LONG_DOUBLE
  62. weak_alias (__pow_compat, powl)
  63. # endif
  64. # ifdef LONG_DOUBLE_COMPAT
  65. /* Work around gas bug "multiple versions for symbol". */
  66. weak_alias (__pow_compat, __pow_compat_alias)
  67. LONG_DOUBLE_COMPAT_CHOOSE_libm_powl (
  68. compat_symbol (libm, __pow_compat_alias, powl, FIRST_VERSION_libm_powl), );
  69. # endif
  70. #endif