complex.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /* GCC Quad-Precision Math Library
  2. Copyright (C) 2010, 2011 Free Software Foundation, Inc.
  3. Written by Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
  4. This file is part of the libquadmath library.
  5. Libquadmath is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Library General Public
  7. License as published by the Free Software Foundation; either
  8. version 2 of the License, or (at your option) any later version.
  9. Libquadmath 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. Library General Public License for more details.
  13. You should have received a copy of the GNU Library General Public
  14. License along with libquadmath; see the file COPYING.LIB. If
  15. not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
  16. Boston, MA 02110-1301, USA. */
  17. #include "quadmath-imp.h"
  18. #ifdef HAVE_FENV_H
  19. # include <fenv.h>
  20. #endif
  21. #define REALPART(z) (__real__(z))
  22. #define IMAGPART(z) (__imag__(z))
  23. #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
  24. __float128
  25. cabsq (__complex128 z)
  26. {
  27. return hypotq (REALPART (z), IMAGPART (z));
  28. }
  29. __complex128
  30. cexpiq (__float128 x)
  31. {
  32. __float128 sinix, cosix;
  33. __complex128 v;
  34. sincosq (x, &sinix, &cosix);
  35. COMPLEX_ASSIGN (v, cosix, sinix);
  36. return v;
  37. }
  38. __float128
  39. cargq (__complex128 z)
  40. {
  41. return atan2q (IMAGPART (z), REALPART (z));
  42. }
  43. __complex128
  44. cpowq (__complex128 base, __complex128 power)
  45. {
  46. return cexpq (power * clogq (base));
  47. }
  48. __complex128
  49. ccosq (__complex128 x)
  50. {
  51. __complex128 y;
  52. COMPLEX_ASSIGN (y, -IMAGPART (x), REALPART (x));
  53. return ccoshq (y);
  54. }