catanq.c 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Return arc tangent of complex __float128 value.
  2. Copyright (C) 1997, 1998 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Contributed by Ulrich Drepper <drepper@cygnus.com>, 1997.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, write to the Free
  15. Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  16. 02111-1307 USA. */
  17. #include "quadmath-imp.h"
  18. __complex128
  19. catanq (__complex128 x)
  20. {
  21. __complex128 res;
  22. int rcls = fpclassifyq (__real__ x);
  23. int icls = fpclassifyq (__imag__ x);
  24. if (rcls <= QUADFP_INFINITE || icls <= QUADFP_INFINITE)
  25. {
  26. if (rcls == QUADFP_INFINITE)
  27. {
  28. __real__ res = copysignq (M_PI_2q, __real__ x);
  29. __imag__ res = copysignq (0.0, __imag__ x);
  30. }
  31. else if (icls == QUADFP_INFINITE)
  32. {
  33. if (rcls >= QUADFP_ZERO)
  34. __real__ res = copysignq (M_PI_2q, __real__ x);
  35. else
  36. __real__ res = nanq ("");
  37. __imag__ res = copysignq (0.0, __imag__ x);
  38. }
  39. else if (icls == QUADFP_ZERO || icls == QUADFP_INFINITE)
  40. {
  41. __real__ res = nanq ("");
  42. __imag__ res = copysignq (0.0, __imag__ x);
  43. }
  44. else
  45. {
  46. __real__ res = nanq ("");
  47. __imag__ res = nanq ("");
  48. }
  49. }
  50. else if (rcls == QUADFP_ZERO && icls == QUADFP_ZERO)
  51. {
  52. res = x;
  53. }
  54. else
  55. {
  56. __float128 r2, num, den;
  57. r2 = __real__ x * __real__ x;
  58. den = 1 - r2 - __imag__ x * __imag__ x;
  59. __real__ res = 0.5 * atan2q (2.0 * __real__ x, den);
  60. num = __imag__ x + 1.0;
  61. num = r2 + num * num;
  62. den = __imag__ x - 1.0;
  63. den = r2 + den * den;
  64. __imag__ res = 0.25 * logq (num / den);
  65. }
  66. return res;
  67. }