This repository has been archived by the owner on May 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathf2.h
276 lines (237 loc) · 7.39 KB
/
mathf2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// -*- C++ -*-
/***************************************************************************
* blitz/mathf2.h Declaration of additional math functions
*
* $Id: mathf2.h,v 1.5 2004/03/09 21:56:48 julianc Exp $
*
* Copyright (C) 1997-2001 Todd Veldhuizen <[email protected]>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Suggestions: [email protected]
* Bugs: [email protected]
*
* For more information, please see the Blitz++ Home Page:
* http://oonumerics.org/blitz/
*
***************************************************************************/
#ifndef BZ_MATHF2_H
#define BZ_MATHF2_H
#ifndef BZ_APPLICS_H
#error <blitz/mathf2.h> should be included via <blitz/applics.h>
#endif
#include <blitz/prettyprint.h>
BZ_NAMESPACE(blitz)
// cexp(z) Complex exponential
template<typename P_numtype1>
class _bz_cexp : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{ return _bz_exp<T_numtype1>::apply(x); }
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "cexp(";
a.prettyPrint(str,format);
str += ")";
}
};
// csqrt(z) Complex square root
template<typename P_numtype1>
class _bz_csqrt : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{ return _bz_sqrt<T_numtype1>::apply(x); }
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "csqrt(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow2 Square
template<typename P_numtype1>
class _bz_pow2 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
return BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow2(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow3 Cube
template<typename P_numtype1>
class _bz_pow3 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
return BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x) *
BZ_NO_PROPAGATE(x);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow3(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow4 Fourth power
template<typename P_numtype1>
class _bz_pow4 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow4(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow5 Fifth power
template<typename P_numtype1>
class _bz_pow5 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1)
* BZ_NO_PROPAGATE(t1);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow5(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow6 Sixth power
template<typename P_numtype1>
class _bz_pow6 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x)
* BZ_NO_PROPAGATE(x);
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow6(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow7 Seventh power
template<typename P_numtype1>
class _bz_pow7 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x)
* BZ_NO_PROPAGATE(x);
return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1)
* BZ_NO_PROPAGATE(x);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow7(";
a.prettyPrint(str,format);
str += ")";
}
};
// pow8 Eighth power
template<typename P_numtype1>
class _bz_pow8 : public OneOperandApplicativeTemplatesBase {
public:
typedef P_numtype1 T_numtype1;
typedef P_numtype1 T_numtype;
static inline T_numtype apply(T_numtype1 x)
{
T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
T_numtype t2 = BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
return BZ_NO_PROPAGATE(t2) * BZ_NO_PROPAGATE(t2);
}
template<typename T1>
static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
const T1& a)
{
str += "pow8(";
a.prettyPrint(str,format);
str += ")";
}
};
/*
* These scalar versions of pow2, pow3, ..., pow8 are provided for
* convenience.
*
* NEEDS_WORK -- include BZ_NO_PROPAGATE for these scalar versions.
*/
// NEEDS_WORK -- make these templates. Rely on specialization to
// handle expression template versions.
#define BZ_DECLARE_POW(T) \
inline T pow2(T x) { return x*x; } \
inline T pow3(T x) { return x*x*x; } \
inline T pow4(T x) { T t1 = x*x; return t1*t1; } \
inline T pow5(T x) { T t1 = x*x; return t1*t1*x; } \
inline T pow6(T x) { T t1 = x*x*x; return t1*t1; } \
inline T pow7(T x) { T t1 = x*x; return t1*t1*t1*x; } \
inline T pow8(T x) { T t1 = x*x, t2=t1*t1; return t2*t2; }
BZ_DECLARE_POW(int)
BZ_DECLARE_POW(float)
BZ_DECLARE_POW(double)
BZ_DECLARE_POW(long double)
#ifdef BZ_HAVE_COMPLEX
BZ_DECLARE_POW(complex<float>)
BZ_DECLARE_POW(complex<double>)
BZ_DECLARE_POW(complex<long double>)
#endif
BZ_NAMESPACE_END
#endif