xref: /netbsd-src/external/gpl3/gcc.old/dist/libquadmath/math/complex.c (revision 627f7eb200a4419d89b531d55fccd2ee3ffdcde0)
1*627f7eb2Smrg /* GCC Quad-Precision Math Library
2*627f7eb2Smrg    Copyright (C) 2010, 2011 Free Software Foundation, Inc.
3*627f7eb2Smrg    Written by Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
4*627f7eb2Smrg 
5*627f7eb2Smrg This file is part of the libquadmath library.
6*627f7eb2Smrg Libquadmath is free software; you can redistribute it and/or
7*627f7eb2Smrg modify it under the terms of the GNU Library General Public
8*627f7eb2Smrg License as published by the Free Software Foundation; either
9*627f7eb2Smrg version 2 of the License, or (at your option) any later version.
10*627f7eb2Smrg 
11*627f7eb2Smrg Libquadmath is distributed in the hope that it will be useful,
12*627f7eb2Smrg but WITHOUT ANY WARRANTY; without even the implied warranty of
13*627f7eb2Smrg MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*627f7eb2Smrg Library General Public License for more details.
15*627f7eb2Smrg 
16*627f7eb2Smrg You should have received a copy of the GNU Library General Public
17*627f7eb2Smrg License along with libquadmath; see the file COPYING.LIB.  If
18*627f7eb2Smrg not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
19*627f7eb2Smrg Boston, MA 02110-1301, USA.  */
20*627f7eb2Smrg 
21*627f7eb2Smrg #include "quadmath-imp.h"
22*627f7eb2Smrg 
23*627f7eb2Smrg #ifdef HAVE_FENV_H
24*627f7eb2Smrg # include <fenv.h>
25*627f7eb2Smrg #endif
26*627f7eb2Smrg 
27*627f7eb2Smrg 
28*627f7eb2Smrg #define REALPART(z) (__real__(z))
29*627f7eb2Smrg #define IMAGPART(z) (__imag__(z))
30*627f7eb2Smrg #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
31*627f7eb2Smrg 
32*627f7eb2Smrg 
33*627f7eb2Smrg __float128
cabsq(__complex128 z)34*627f7eb2Smrg cabsq (__complex128 z)
35*627f7eb2Smrg {
36*627f7eb2Smrg   return hypotq (REALPART (z), IMAGPART (z));
37*627f7eb2Smrg }
38*627f7eb2Smrg 
39*627f7eb2Smrg 
40*627f7eb2Smrg __complex128
cexpiq(__float128 x)41*627f7eb2Smrg cexpiq (__float128 x)
42*627f7eb2Smrg {
43*627f7eb2Smrg   __float128 sinix, cosix;
44*627f7eb2Smrg   __complex128 v;
45*627f7eb2Smrg   sincosq (x, &sinix, &cosix);
46*627f7eb2Smrg   COMPLEX_ASSIGN (v, cosix, sinix);
47*627f7eb2Smrg   return v;
48*627f7eb2Smrg }
49*627f7eb2Smrg 
50*627f7eb2Smrg 
51*627f7eb2Smrg __float128
cargq(__complex128 z)52*627f7eb2Smrg cargq (__complex128 z)
53*627f7eb2Smrg {
54*627f7eb2Smrg   return atan2q (IMAGPART (z), REALPART (z));
55*627f7eb2Smrg }
56*627f7eb2Smrg 
57*627f7eb2Smrg 
58*627f7eb2Smrg __complex128
cpowq(__complex128 base,__complex128 power)59*627f7eb2Smrg cpowq (__complex128 base, __complex128 power)
60*627f7eb2Smrg {
61*627f7eb2Smrg   return cexpq (power * clogq (base));
62*627f7eb2Smrg }
63*627f7eb2Smrg 
64*627f7eb2Smrg 
65*627f7eb2Smrg __complex128
ccosq(__complex128 x)66*627f7eb2Smrg ccosq (__complex128 x)
67*627f7eb2Smrg {
68*627f7eb2Smrg   __complex128 y;
69*627f7eb2Smrg 
70*627f7eb2Smrg   COMPLEX_ASSIGN (y, -IMAGPART (x), REALPART (x));
71*627f7eb2Smrg   return ccoshq (y);
72*627f7eb2Smrg }
73