w_powl.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 __NO_LONG_DOUBLE_MATH
  18. /* wrapper powl */
  19. long double
  20. powl (long double x, long double y)
  21. {
  22. #if __UCLIBC_HAS_FENV__
  23. long double z = (long double) __ieee754_pow ((double) x, (double) y);
  24. if (__builtin_expect (!isfinite (z), 0))
  25. {
  26. if (_LIB_VERSION != _IEEE_)
  27. {
  28. if (isnan (x))
  29. {
  30. if (y == 0.0L)
  31. /* pow(NaN,0.0) */
  32. return __kernel_standard_l (x, y, 242);
  33. }
  34. else if (isfinite (x) && isfinite (y))
  35. {
  36. if (isnan (z))
  37. /* pow neg**non-int */
  38. return __kernel_standard_l (x, y, 224);
  39. else if (x == 0.0L && y < 0.0L)
  40. {
  41. if (signbit (x) && signbit (z))
  42. /* pow(-0.0,negative) */
  43. return __kernel_standard_l (x, y, 223);
  44. else
  45. /* pow(+0.0,negative) */
  46. return __kernel_standard_l (x, y, 243);
  47. }
  48. else
  49. /* pow overflow */
  50. return __kernel_standard_l (x, y, 221);
  51. }
  52. }
  53. }
  54. else if (__builtin_expect (z == 0.0L, 0) && isfinite (x) && isfinite (y)
  55. && _LIB_VERSION != _IEEE_)
  56. {
  57. if (x == 0.0L)
  58. {
  59. if (y == 0.0L)
  60. /* pow(0.0,0.0) */
  61. return __kernel_standard_l (x, y, 220);
  62. }
  63. else
  64. /* pow underflow */
  65. return __kernel_standard_l (x, y, 222);
  66. }
  67. return z;
  68. # else
  69. return (long double) __ieee754_pow ((double) x, (double) y);
  70. # endif /* __UCLIBC_HAS_FENV__ */
  71. }
  72. #endif /* __NO_LONG_DOUBLE_MATH */