k_standardl.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /* Implement __kernel_standard_l.
  2. Copyright (C) 2012-2026 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  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. <https://www.gnu.org/licenses/>.
  15. Parts based on k_standard.c from fdlibm: */
  16. /* @(#)k_standard.c 5.1 93/09/24 */
  17. /*
  18. * ====================================================
  19. * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved.
  20. *
  21. * Developed at SunPro, a Sun Microsystems, Inc. business.
  22. * Permission to use, copy, modify, and distribute this
  23. * software is freely granted, provided that this notice
  24. * is preserved.
  25. * ====================================================
  26. */
  27. #include <math.h>
  28. #include <math-barriers.h>
  29. #include <math-svid-compat.h>
  30. #include <fenv.h>
  31. #include <float.h>
  32. #include <errno.h>
  33. #if LIBM_SVID_COMPAT
  34. static double zero = 0.0;
  35. /* Handle errors for a libm function as specified by TYPE (see
  36. comments in k_standard.c for details), with arguments X and Y,
  37. returning the appropriate return value for that function. */
  38. long double
  39. __kernel_standard_l (long double x, long double y, int type)
  40. {
  41. double dx, dy;
  42. struct exception exc;
  43. fenv_t env;
  44. feholdexcept (&env);
  45. dx = x;
  46. dy = y;
  47. math_force_eval (dx);
  48. math_force_eval (dy);
  49. fesetenv (&env);
  50. switch (type)
  51. {
  52. case 221:
  53. /* powl (x, y) overflow. */
  54. exc.arg1 = dx;
  55. exc.arg2 = dy;
  56. exc.type = OVERFLOW;
  57. exc.name = (char *) "powl";
  58. if (_LIB_VERSION == _SVID_)
  59. {
  60. exc.retval = HUGE;
  61. y *= 0.5;
  62. if (x < zero && rintl (y) != y)
  63. exc.retval = -HUGE;
  64. }
  65. else
  66. {
  67. exc.retval = HUGE_VAL;
  68. y *= 0.5;
  69. if (x < zero && rintl (y) != y)
  70. exc.retval = -HUGE_VAL;
  71. }
  72. if (_LIB_VERSION == _POSIX_)
  73. __set_errno (ERANGE);
  74. else if (!matherr (&exc))
  75. __set_errno (ERANGE);
  76. return exc.retval;
  77. case 222:
  78. /* powl (x, y) underflow. */
  79. exc.arg1 = dx;
  80. exc.arg2 = dy;
  81. exc.type = UNDERFLOW;
  82. exc.name = (char *) "powl";
  83. exc.retval = zero;
  84. y *= 0.5;
  85. if (x < zero && rintl (y) != y)
  86. exc.retval = -zero;
  87. if (_LIB_VERSION == _POSIX_)
  88. __set_errno (ERANGE);
  89. else if (!matherr (&exc))
  90. __set_errno (ERANGE);
  91. return exc.retval;
  92. default:
  93. return __kernel_standard (dx, dy, type);
  94. }
  95. }
  96. #endif