2
/***************************************************************************
3
* blitz/mathf2.h Declaration of additional math functions
5
* $Id: mathf2.h,v 1.5 2004/03/09 21:56:48 julianc Exp $
7
* Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
9
* This program is free software; you can redistribute it and/or
10
* modify it under the terms of the GNU General Public License
11
* as published by the Free Software Foundation; either version 2
12
* of the License, or (at your option) any later version.
14
* This program is distributed in the hope that it will be useful,
15
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
* GNU General Public License for more details.
19
* Suggestions: blitz-dev@oonumerics.org
20
* Bugs: blitz-bugs@oonumerics.org
22
* For more information, please see the Blitz++ Home Page:
23
* http://oonumerics.org/blitz/
25
***************************************************************************/
31
#error <blitz/mathf2.h> should be included via <blitz/applics.h>
34
#include <blitz/prettyprint.h>
38
// cexp(z) Complex exponential
39
template<typename P_numtype1>
40
class _bz_cexp : public OneOperandApplicativeTemplatesBase {
42
typedef P_numtype1 T_numtype1;
43
typedef P_numtype1 T_numtype;
45
static inline T_numtype apply(T_numtype1 x)
46
{ return _bz_exp<T_numtype1>::apply(x); }
49
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
53
a.prettyPrint(str,format);
58
// csqrt(z) Complex square root
59
template<typename P_numtype1>
60
class _bz_csqrt : public OneOperandApplicativeTemplatesBase {
62
typedef P_numtype1 T_numtype1;
63
typedef P_numtype1 T_numtype;
65
static inline T_numtype apply(T_numtype1 x)
66
{ return _bz_sqrt<T_numtype1>::apply(x); }
69
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
73
a.prettyPrint(str,format);
79
template<typename P_numtype1>
80
class _bz_pow2 : public OneOperandApplicativeTemplatesBase {
82
typedef P_numtype1 T_numtype1;
83
typedef P_numtype1 T_numtype;
85
static inline T_numtype apply(T_numtype1 x)
87
return BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
91
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
95
a.prettyPrint(str,format);
101
template<typename P_numtype1>
102
class _bz_pow3 : public OneOperandApplicativeTemplatesBase {
104
typedef P_numtype1 T_numtype1;
105
typedef P_numtype1 T_numtype;
107
static inline T_numtype apply(T_numtype1 x)
109
return BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x) *
113
template<typename T1>
114
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
118
a.prettyPrint(str,format);
124
template<typename P_numtype1>
125
class _bz_pow4 : public OneOperandApplicativeTemplatesBase {
127
typedef P_numtype1 T_numtype1;
128
typedef P_numtype1 T_numtype;
130
static inline T_numtype apply(T_numtype1 x)
132
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
133
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
136
template<typename T1>
137
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
141
a.prettyPrint(str,format);
147
template<typename P_numtype1>
148
class _bz_pow5 : public OneOperandApplicativeTemplatesBase {
150
typedef P_numtype1 T_numtype1;
151
typedef P_numtype1 T_numtype;
153
static inline T_numtype apply(T_numtype1 x)
155
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
156
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1)
157
* BZ_NO_PROPAGATE(t1);
160
template<typename T1>
161
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
165
a.prettyPrint(str,format);
171
template<typename P_numtype1>
172
class _bz_pow6 : public OneOperandApplicativeTemplatesBase {
174
typedef P_numtype1 T_numtype1;
175
typedef P_numtype1 T_numtype;
177
static inline T_numtype apply(T_numtype1 x)
179
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x)
180
* BZ_NO_PROPAGATE(x);
181
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
184
template<typename T1>
185
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
189
a.prettyPrint(str,format);
195
// pow7 Seventh power
196
template<typename P_numtype1>
197
class _bz_pow7 : public OneOperandApplicativeTemplatesBase {
199
typedef P_numtype1 T_numtype1;
200
typedef P_numtype1 T_numtype;
202
static inline T_numtype apply(T_numtype1 x)
204
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x)
205
* BZ_NO_PROPAGATE(x);
206
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1)
207
* BZ_NO_PROPAGATE(x);
210
template<typename T1>
211
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
215
a.prettyPrint(str,format);
221
template<typename P_numtype1>
222
class _bz_pow8 : public OneOperandApplicativeTemplatesBase {
224
typedef P_numtype1 T_numtype1;
225
typedef P_numtype1 T_numtype;
227
static inline T_numtype apply(T_numtype1 x)
229
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
230
T_numtype t2 = BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
231
return BZ_NO_PROPAGATE(t2) * BZ_NO_PROPAGATE(t2);
234
template<typename T1>
235
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
239
a.prettyPrint(str,format);
245
* These scalar versions of pow2, pow3, ..., pow8 are provided for
248
* NEEDS_WORK -- include BZ_NO_PROPAGATE for these scalar versions.
251
// NEEDS_WORK -- make these templates. Rely on specialization to
252
// handle expression template versions.
254
#define BZ_DECLARE_POW(T) \
255
inline T pow2(T x) { return x*x; } \
256
inline T pow3(T x) { return x*x*x; } \
257
inline T pow4(T x) { T t1 = x*x; return t1*t1; } \
258
inline T pow5(T x) { T t1 = x*x; return t1*t1*x; } \
259
inline T pow6(T x) { T t1 = x*x*x; return t1*t1; } \
260
inline T pow7(T x) { T t1 = x*x; return t1*t1*t1*x; } \
261
inline T pow8(T x) { T t1 = x*x, t2=t1*t1; return t2*t2; }
264
BZ_DECLARE_POW(float)
265
BZ_DECLARE_POW(double)
266
BZ_DECLARE_POW(long double)
268
#ifdef BZ_HAVE_COMPLEX
269
BZ_DECLARE_POW(complex<float>)
270
BZ_DECLARE_POW(complex<double>)
271
BZ_DECLARE_POW(complex<long double>)