k_standardl.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. /* Implement __kernel_standard_l.
  2. Copyright (C) 2012-2016 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. <http://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_private.h"
  29. #include <fenv.h>
  30. #include <float.h>
  31. #include <errno.h>
  32. static double zero = 0.0;
  33. /* Handle errors for a libm function as specified by TYPE (see
  34. comments in k_standard.c for details), with arguments X and Y,
  35. returning the appropriate return value for that function. */
  36. long double
  37. __kernel_standard_l (long double x, long double y, int type)
  38. {
  39. double dx, dy;
  40. struct exception exc;
  41. fenv_t env;
  42. feholdexcept (&env);
  43. dx = x;
  44. dy = y;
  45. math_force_eval (dx);
  46. math_force_eval (dy);
  47. fesetenv (&env);
  48. switch (type)
  49. {
  50. case 221:
  51. /* powl (x, y) overflow. */
  52. exc.arg1 = dx;
  53. exc.arg2 = dy;
  54. exc.type = OVERFLOW;
  55. exc.name = (char *) "powl";
  56. if (_LIB_VERSION == _SVID_)
  57. {
  58. exc.retval = HUGE;
  59. y *= 0.5;
  60. if (x < zero && rint (y) != y)
  61. exc.retval = -HUGE;
  62. }
  63. else
  64. {
  65. exc.retval = HUGE_VAL;
  66. y *= 0.5;
  67. if (x < zero && rint (y) != y)
  68. exc.retval = -HUGE_VAL;
  69. }
  70. if (_LIB_VERSION == _POSIX_)
  71. __set_errno (ERANGE);
  72. else if (!matherr (&exc))
  73. __set_errno (ERANGE);
  74. return exc.retval;
  75. case 222:
  76. /* powl (x, y) underflow. */
  77. exc.arg1 = dx;
  78. exc.arg2 = dy;
  79. exc.type = UNDERFLOW;
  80. exc.name = (char *) "powl";
  81. exc.retval = zero;
  82. y *= 0.5;
  83. if (x < zero && rint (y) != y)
  84. exc.retval = -zero;
  85. if (_LIB_VERSION == _POSIX_)
  86. __set_errno (ERANGE);
  87. else if (!matherr (&exc))
  88. __set_errno (ERANGE);
  89. return exc.retval;
  90. default:
  91. return __kernel_standard (dx, dy, type);
  92. }
  93. }