1 // The template and inlines for the -*- C++ -*- complex number classes.
3 // Copyright (C) 1997-1999 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the
7 // terms of the GNU General Public License as published by the
8 // Free Software Foundation; either version 2, or (at your option)
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this library; see the file COPYING. If not, write to the Free
18 // Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307,
21 // As a special exception, you may use this file as part of a free software
22 // library without restriction. Specifically, if other files instantiate
23 // templates or use macros or inline functions from this file, or you compile
24 // this file and link it with other files to produce an executable, this
25 // file does not by itself cause the resulting executable to be covered by
26 // the GNU General Public License. This exception does not however
27 // invalidate any other reasons why the executable file might be covered by
28 // the GNU General Public License.
30 #include <bits/std_cmath.h>
31 #include <bits/std_complex.h>
33 // This is a ISO C 9X header.
34 #include <math/mathconf.h>
39 # define FCT(name) ::name
47 abs(const complex<FLT>& __x)
48 { return FCT(cabs)(__x._M_value); }
52 arg(const complex<FLT>& __x)
53 { return FCT(carg)(__x._M_value); }
57 polar(const FLT& __rho, const FLT& __theta)
59 #if defined _G_HAVE_SINCOS && !defined __osf__
60 // Although sincos does exist on OSF3.2 and OSF4.0 we cannot use it
61 // since the necessary types are not defined in the headers.
63 FCT(sincos)(__theta, &__sinx, &__cosx);
64 return complex<FLT>(__rho * __cosx, __rho * __sinx);
66 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
67 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
68 complex<FLT> __tmpf(__rho * FCT(cos)(__theta),
69 __rho * FCT(sin)(__theta));
72 return complex<FLT>(__rho * FCT(cos)(__theta),
73 __rho * FCT(sin)(__theta));
80 cos(const complex<FLT>& __x)
81 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
82 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
84 complex<FLT> __tmpf(FCT(ccos)(__x._M_value));
88 { return complex<FLT>(FCT(ccos)(__x._M_value)); }
93 cosh(const complex<FLT>& __x)
94 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
95 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
97 complex<FLT> __tmpf(FCT(ccosh)(__x._M_value));
101 { return complex<FLT>(FCT(ccosh)(__x._M_value)); }
106 exp(const complex<FLT>& __x)
107 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
108 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
110 complex<FLT> __tmpf(FCT(cexp)(__x._M_value));
114 { return complex<FLT>(FCT(cexp)(__x._M_value)); }
119 log(const complex<FLT>& __x)
120 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
121 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
123 complex<FLT> __tmpf(FCT(c_log)(__x._M_value));
127 { return complex<FLT>(FCT(c_log)(__x._M_value)); }
132 log10(const complex<FLT>& __x)
133 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
134 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
136 complex<FLT> __tmpf(FCT(clog10)(__x._M_value));
140 { return complex<FLT>(FCT(clog10)(__x._M_value)); }
145 pow(const complex<FLT>& __x, int __n)
146 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
147 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
149 complex<FLT> __tmpf(FCT(cexp) (__n * FCT(c_log)(__x._M_value)));
153 { return complex<FLT>(FCT(cexp) (__n * FCT(c_log)(__x._M_value))); }
159 pow(const complex<FLT>& __x, const FLT& __y)
160 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
161 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
163 complex<FLT> __tmpf(FCT(cexp) (__y * FCT(c_log)(__x._M_value)));
167 { return complex<FLT>(FCT(cexp) (__y * FCT(c_log)(__x._M_value))); }
172 pow(const complex<FLT>& __x, const complex<FLT>& __y)
173 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
174 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
176 complex<FLT> __tmpf(FCT(cpow)(__x._M_value, __y._M_value));
180 { return complex<FLT>(FCT(cpow)(__x._M_value, __y._M_value)); }
185 pow(const FLT& __x, const complex<FLT>& __y)
186 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
187 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
189 complex<FLT> __tmpf(FCT(cexp)(__y._M_value * FCT(log)(__x)));
193 { return complex<FLT>(FCT(cexp)(__y._M_value * FCT(log)(__x))); }
198 sin(const complex<FLT>& __x)
199 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
200 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
202 complex<FLT> __tmpf(FCT(csin)(__x._M_value));
206 { return complex<FLT>(FCT(csin)(__x._M_value)); }
211 sinh(const complex<FLT>& __x)
212 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
213 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
215 complex<FLT> __tmpf(FCT(csinh)(__x._M_value));
219 { return complex<FLT>(FCT(csinh)(__x._M_value)); }
224 sqrt(const complex<FLT>& __x)
225 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
226 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
228 complex<FLT> __tmpf(FCT(csqrt)(__x._M_value));
232 { return complex<FLT>(FCT(csqrt)(__x._M_value)); }
237 tan(const complex<FLT>& __x)
238 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
239 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
241 complex<FLT> __tmpf(FCT(ctan)(__x._M_value));
245 { return complex<FLT>(FCT(ctan)(__x._M_value)); }
250 tanh(const complex<FLT>& __x)
251 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
252 && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
254 complex<FLT> __tmpf(FCT(ctanh)(__x._M_value));
258 { return complex<FLT>(FCT(ctanh)(__x._M_value)); }