]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libgfortran/generated/exp_c8.c
1 /* Complex exponential functions
2 Copyright 2002, 2004 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>
5 This file is part of the GNU Fortran 95 runtime library (libgfor).
7 Libgfortran is free software; you can redistribute it and/or
8 modify it under the terms of the GNU Lesser General Public
9 License as published by the Free Software Foundation; either
10 version 2.1 of the License, or (at your option) any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU Lesser General Public License for more details.
17 You should have received a copy of the GNU Lesser General Public
18 License along with libgfor; see the file COPYING.LIB. If not,
19 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 #include "libgfortran.h"
28 cabs (GFC_COMPLEX_8 z
)
30 return hypot (REALPART (z
), IMAGPART (z
));
33 /* Complex argument. The angle made with the +ve real axis. Range 0-2pi. */
35 carg (GFC_COMPLEX_8 z
)
39 arg
= atan2 (IMAGPART (z
), REALPART (z
));
41 return arg
+ 2 * M_PI
;
46 /* exp(z) = exp(a)*(cos(b) + isin(b)) */
48 cexp (GFC_COMPLEX_8 z
)
56 COMPLEX_ASSIGN (v
, cos (b
), sin (b
));
60 /* log(z) = log (cabs(z)) + i*carg(z) */
62 clog (GFC_COMPLEX_8 z
)
66 COMPLEX_ASSIGN (v
, log (cabs (z
)), carg (z
));
70 /* log10(z) = log10 (cabs(z)) + i*carg(z) */
72 clog10 (GFC_COMPLEX_8 z
)
76 COMPLEX_ASSIGN (v
, log10 (cabs (z
)), carg (z
));
80 /* pow(base, power) = cexp (power * clog (base)) */
82 cpow (GFC_COMPLEX_8 base
, GFC_COMPLEX_8 power
)
84 return cexp (power
* clog (base
));
87 /* sqrt(z). Algorithm pulled from glibc. */
89 csqrt (GFC_COMPLEX_8 z
)
101 COMPLEX_ASSIGN (v
, 0.0, copysign (sqrt (-re
), im
));
105 COMPLEX_ASSIGN (v
, fabs (sqrt (re
)),
113 r
= sqrt (0.5 * fabs (im
));
115 COMPLEX_ASSIGN (v
, copysign (r
, im
), r
);
122 /* Use the identity 2 Re res Im res = Im x
123 to avoid cancellation error in d +/- Re x. */
126 r
= sqrt (0.5 * d
+ 0.5 * re
);
131 s
= sqrt (0.5 * d
- 0.5 * re
);
132 r
= fabs ((0.5 * im
) / s
);
135 COMPLEX_ASSIGN (v
, r
, copysign (s
, im
));