/sysdeps/ieee754/ldbl-128ibm/s_cprojl.c

https://github.com/cmatthew/Lind-GlibC · C · 54 lines · 28 code · 6 blank · 20 comment · 9 complexity · 9a50dc4b0316cb0cf439b35a74033da9 MD5 · raw file

  1. /* Compute projection of complex long double value to Riemann sphere.
  2. Copyright (C) 1997,1999,2006 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 <complex.h>
  18. #include <math.h>
  19. #include <math_ldbl_opt.h>
  20. __complex__ long double
  21. __cprojl (__complex__ long double x)
  22. {
  23. __complex__ long double res;
  24. if (isnan (__real__ x) && isnan (__imag__ x))
  25. return x;
  26. else if (!isfinite (__real__ x) || !isfinite (__imag__ x))
  27. {
  28. __real__ res = INFINITY;
  29. __imag__ res = __copysignl (0.0, __imag__ x);
  30. }
  31. else
  32. {
  33. long double den = (__real__ x * __real__ x + __imag__ x * __imag__ x
  34. + 1.0);
  35. __real__ res = (2.0 * __real__ x) / den;
  36. __imag__ res = (2.0 * __imag__ x) / den;
  37. /* __gcc_qmul does not respect -0.0 so we need the following fixup. */
  38. if (__real__ x == 0.0)
  39. __real__ res = __real__ x;
  40. if (__imag__ x == 0.0)
  41. __imag__ res = __imag__ x;
  42. }
  43. return res;
  44. }
  45. long_double_symbol (libm, __cprojl, cprojl);