OSDN Git Service

2000-08-30 Benjamin Kosnik <bkoz@redhat.com>
[pf3gnuchains/gcc-fork.git] / libstdc++-v3 / src / complex.cc
1 // The template and inlines for the -*- C++ -*- complex number classes.
2
3 // Copyright (C) 1997-1999 Free Software Foundation, Inc.
4 //
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)
9 // any later version.
10
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.
15
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,
19 // USA.
20
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.
29
30 #include <bits/std_cmath.h>
31 #include <bits/std_complex.h>
32
33 // This is a ISO C 9X header.
34 #include <math/mathconf.h>
35 #undef complex
36
37 #ifndef FLT
38 # define FLT double
39 # define FCT(name) ::name
40 #endif
41
42 namespace std
43 {
44     
45     template<>
46     FLT
47     abs(const complex<FLT>& __x)
48     { return FCT(cabs)(__x._M_value); }
49
50     template<>
51     FLT
52     arg(const complex<FLT>& __x)
53     { return FCT(carg)(__x._M_value); }
54
55     template<>
56     complex<FLT>
57     polar(const FLT& __rho, const FLT& __theta)
58     {
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.
62       FLT __sinx, __cosx;
63       FCT(sincos)(__theta, &__sinx, &__cosx);
64       return complex<FLT>(__rho * __cosx, __rho * __sinx);
65 #else
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));
70       return __tmpf;
71 #else
72        return complex<FLT>(__rho * FCT(cos)(__theta),
73                           __rho * FCT(sin)(__theta));
74 #endif
75 #endif
76     }
77
78     template<>
79     complex<FLT>
80     cos(const complex<FLT>& __x)
81 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
82       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
83     {
84       complex<FLT> __tmpf(FCT(ccos)(__x._M_value));
85       return __tmpf;
86     }
87 #else
88     { return complex<FLT>(FCT(ccos)(__x._M_value)); }
89 #endif
90
91     template<>
92     complex<FLT>
93     cosh(const complex<FLT>& __x)
94 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
95       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
96     {
97       complex<FLT> __tmpf(FCT(ccosh)(__x._M_value));
98       return __tmpf;
99     }
100 #else
101     { return complex<FLT>(FCT(ccosh)(__x._M_value)); }
102 #endif
103
104     template<>
105     complex<FLT>
106     exp(const complex<FLT>& __x)
107 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
108       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
109     {
110       complex<FLT> __tmpf(FCT(cexp)(__x._M_value));
111       return __tmpf;
112     }
113 #else
114     { return complex<FLT>(FCT(cexp)(__x._M_value)); }
115 #endif
116
117     template<>
118     complex<FLT>
119     log(const complex<FLT>& __x)
120 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
121       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
122     {
123       complex<FLT> __tmpf(FCT(c_log)(__x._M_value));
124       return __tmpf;
125     }
126 #else
127     { return complex<FLT>(FCT(c_log)(__x._M_value)); }
128 #endif
129
130     template<>
131     complex<FLT>
132     log10(const complex<FLT>& __x)
133 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
134       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
135     {
136       complex<FLT> __tmpf(FCT(clog10)(__x._M_value));
137       return __tmpf;
138     }
139 #else
140     { return complex<FLT>(FCT(clog10)(__x._M_value)); }
141 #endif
142
143     template<>
144     complex<FLT>
145     pow(const complex<FLT>& __x, int __n)
146 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
147       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
148     {
149       complex<FLT> __tmpf(FCT(cexp) (__n * FCT(c_log)(__x._M_value)));
150       return __tmpf;
151     }
152 #else
153     { return complex<FLT>(FCT(cexp) (__n * FCT(c_log)(__x._M_value))); }
154 #endif
155
156
157     template<>
158     complex<FLT>
159     pow(const complex<FLT>& __x, const FLT& __y)
160 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
161       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
162     {
163       complex<FLT> __tmpf(FCT(cexp) (__y * FCT(c_log)(__x._M_value)));
164       return __tmpf;
165     }
166 #else
167     { return complex<FLT>(FCT(cexp) (__y * FCT(c_log)(__x._M_value))); }
168 #endif
169
170     template<>
171     complex<FLT>
172     pow(const complex<FLT>& __x, const complex<FLT>& __y)
173 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
174       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
175     {
176       complex<FLT> __tmpf(FCT(cpow)(__x._M_value, __y._M_value));
177       return __tmpf;
178     }
179 #else
180     { return complex<FLT>(FCT(cpow)(__x._M_value, __y._M_value)); }
181 #endif
182
183     template<>
184     complex<FLT>
185     pow(const FLT& __x, const complex<FLT>& __y)
186 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
187       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
188     {
189       complex<FLT> __tmpf(FCT(cexp)(__y._M_value * FCT(log)(__x)));
190       return __tmpf;
191     }
192 #else
193     { return complex<FLT>(FCT(cexp)(__y._M_value * FCT(log)(__x))); }
194 #endif
195
196     template<>
197     complex<FLT>
198     sin(const complex<FLT>& __x)
199 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
200       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
201     {
202       complex<FLT> __tmpf(FCT(csin)(__x._M_value));
203       return __tmpf;
204     }
205 #else
206     { return complex<FLT>(FCT(csin)(__x._M_value)); }
207 #endif
208
209     template<>
210     complex<FLT>
211     sinh(const complex<FLT>& __x)
212 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
213       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
214     {
215       complex<FLT> __tmpf(FCT(csinh)(__x._M_value));
216       return __tmpf;
217     }
218 #else
219     { return complex<FLT>(FCT(csinh)(__x._M_value)); }
220 #endif
221
222     template<>
223     complex<FLT>
224     sqrt(const complex<FLT>& __x)
225 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
226       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
227     {
228       complex<FLT> __tmpf(FCT(csqrt)(__x._M_value));
229       return __tmpf;
230     }
231 #else
232     { return complex<FLT>(FCT(csqrt)(__x._M_value)); }
233 #endif
234
235     template<>
236     complex<FLT>
237     tan(const complex<FLT>& __x)
238 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
239       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
240     {
241       complex<FLT> __tmpf(FCT(ctan)(__x._M_value));
242       return __tmpf;
243     }
244 #else
245      { return complex<FLT>(FCT(ctan)(__x._M_value)); }
246 #endif
247
248     template<>
249     complex<FLT>
250     tanh(const complex<FLT>& __x)
251 #if defined(_GLIBCPP_BUGGY_FLOAT_COMPLEX) \
252       && defined(_GLIBCPP_FLOAT_SPECIALIZATION)
253     {
254       complex<FLT> __tmpf(FCT(ctanh)(__x._M_value));
255       return __tmpf;
256     }
257 #else
258      { return complex<FLT>(FCT(ctanh)(__x._M_value)); }
259 #endif
260     
261 } // namespace std
262
263
264
265
266
267
268
269
270
271
272
273
274