~ubuntu-branches/ubuntu/utopic/blitz++/utopic

« back to all changes in this revision

Viewing changes to blitz/mathf2.h

  • Committer: Package Import Robot
  • Author(s): Christophe Trophime
  • Date: 2012-07-06 09:15:30 UTC
  • mfrom: (11.1.5 sid)
  • Revision ID: package-import@ubuntu.com-20120706091530-vzrb8zf0vpbf8tp9
Tags: 1:0.10-1
* New upstream release
  Closes: #679407
* debian/rules:
  - update for new release
  - add override_dh_auto_test target
  - regenerate configure and Makefile.am
* debian/control:
  - add libtool, automake to BuildDepends
* debian/libblitz-doc.install
  - modify path for html files
* remove uneeded patches
* add examples.patch

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
// -*- C++ -*-
2
 
/***************************************************************************
3
 
 * blitz/mathf2.h  Declaration of additional math functions
4
 
 *
5
 
 * $Id: mathf2.h,v 1.5 2004/03/09 21:56:48 julianc Exp $
6
 
 *
7
 
 * Copyright (C) 1997-2001 Todd Veldhuizen <tveldhui@oonumerics.org>
8
 
 *
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.
13
 
 *
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.
18
 
 *
19
 
 * Suggestions:          blitz-dev@oonumerics.org
20
 
 * Bugs:                 blitz-bugs@oonumerics.org
21
 
 *
22
 
 * For more information, please see the Blitz++ Home Page:
23
 
 *    http://oonumerics.org/blitz/
24
 
 *
25
 
 ***************************************************************************/
26
 
 
27
 
#ifndef BZ_MATHF2_H
28
 
#define BZ_MATHF2_H
29
 
 
30
 
#ifndef BZ_APPLICS_H
31
 
 #error <blitz/mathf2.h> should be included via <blitz/applics.h>
32
 
#endif
33
 
 
34
 
#include <blitz/prettyprint.h>
35
 
 
36
 
BZ_NAMESPACE(blitz)
37
 
 
38
 
// cexp(z)     Complex exponential
39
 
template<typename P_numtype1>
40
 
class _bz_cexp : public OneOperandApplicativeTemplatesBase {
41
 
public:
42
 
    typedef P_numtype1 T_numtype1;
43
 
    typedef P_numtype1 T_numtype;
44
 
 
45
 
    static inline T_numtype apply(T_numtype1 x)
46
 
    { return _bz_exp<T_numtype1>::apply(x); }
47
 
 
48
 
    template<typename T1>
49
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
50
 
        const T1& a)
51
 
    {
52
 
        str += "cexp(";
53
 
        a.prettyPrint(str,format);
54
 
        str += ")";
55
 
    }
56
 
};
57
 
 
58
 
// csqrt(z)    Complex square root
59
 
template<typename P_numtype1>
60
 
class _bz_csqrt : public OneOperandApplicativeTemplatesBase {
61
 
public:
62
 
    typedef P_numtype1 T_numtype1;
63
 
    typedef P_numtype1 T_numtype;
64
 
 
65
 
    static inline T_numtype apply(T_numtype1 x)
66
 
    { return _bz_sqrt<T_numtype1>::apply(x); }
67
 
 
68
 
    template<typename T1>
69
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
70
 
        const T1& a)
71
 
    {
72
 
        str += "csqrt(";
73
 
        a.prettyPrint(str,format);
74
 
        str += ")";
75
 
    }
76
 
};
77
 
 
78
 
// pow2        Square
79
 
template<typename P_numtype1>
80
 
class _bz_pow2 : public OneOperandApplicativeTemplatesBase {
81
 
public:
82
 
    typedef P_numtype1 T_numtype1;
83
 
    typedef P_numtype1 T_numtype;
84
 
 
85
 
    static inline T_numtype apply(T_numtype1 x)
86
 
    { 
87
 
        return BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
88
 
    }
89
 
 
90
 
    template<typename T1>
91
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
92
 
        const T1& a)
93
 
    {
94
 
        str += "pow2(";
95
 
        a.prettyPrint(str,format);
96
 
        str += ")";
97
 
    }
98
 
};
99
 
 
100
 
// pow3        Cube
101
 
template<typename P_numtype1>
102
 
class _bz_pow3 : public OneOperandApplicativeTemplatesBase {
103
 
public:
104
 
    typedef P_numtype1 T_numtype1;
105
 
    typedef P_numtype1 T_numtype;
106
 
 
107
 
    static inline T_numtype apply(T_numtype1 x)
108
 
    { 
109
 
        return BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x) *
110
 
          BZ_NO_PROPAGATE(x);
111
 
    }
112
 
 
113
 
    template<typename T1>
114
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
115
 
        const T1& a)
116
 
    {
117
 
        str += "pow3(";
118
 
        a.prettyPrint(str,format);
119
 
        str += ")";
120
 
    }
121
 
};
122
 
 
123
 
// pow4        Fourth power
124
 
template<typename P_numtype1>
125
 
class _bz_pow4 : public OneOperandApplicativeTemplatesBase {
126
 
public:
127
 
    typedef P_numtype1 T_numtype1;
128
 
    typedef P_numtype1 T_numtype;
129
 
 
130
 
    static inline T_numtype apply(T_numtype1 x)
131
 
    { 
132
 
        T_numtype t1 = BZ_NO_PROPAGATE(x) * BZ_NO_PROPAGATE(x);
133
 
        return BZ_NO_PROPAGATE(t1) * BZ_NO_PROPAGATE(t1);
134
 
    }
135
 
 
136
 
    template<typename T1>
137
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
138
 
        const T1& a)
139
 
    {
140
 
        str += "pow4(";
141
 
        a.prettyPrint(str,format);
142
 
        str += ")";
143
 
    }
144
 
};
145
 
 
146
 
// pow5        Fifth power
147
 
template<typename P_numtype1>
148
 
class _bz_pow5 : public OneOperandApplicativeTemplatesBase {
149
 
public:
150
 
    typedef P_numtype1 T_numtype1;
151
 
    typedef P_numtype1 T_numtype;
152
 
 
153
 
    static inline T_numtype apply(T_numtype1 x)
154
 
    {
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);
158
 
    }
159
 
 
160
 
    template<typename T1>
161
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
162
 
        const T1& a)
163
 
    {
164
 
        str += "pow5(";
165
 
        a.prettyPrint(str,format);
166
 
        str += ")";
167
 
    }
168
 
};
169
 
 
170
 
// pow6        Sixth power
171
 
template<typename P_numtype1>
172
 
class _bz_pow6 : public OneOperandApplicativeTemplatesBase {
173
 
public:
174
 
    typedef P_numtype1 T_numtype1;
175
 
    typedef P_numtype1 T_numtype;
176
 
 
177
 
    static inline T_numtype apply(T_numtype1 x)
178
 
    {
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);
182
 
    }
183
 
 
184
 
    template<typename T1>
185
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
186
 
        const T1& a)
187
 
    {
188
 
        str += "pow6(";
189
 
        a.prettyPrint(str,format);
190
 
        str += ")";
191
 
    }
192
 
};
193
 
 
194
 
 
195
 
// pow7        Seventh power
196
 
template<typename P_numtype1>
197
 
class _bz_pow7 : public OneOperandApplicativeTemplatesBase {
198
 
public:
199
 
    typedef P_numtype1 T_numtype1;
200
 
    typedef P_numtype1 T_numtype;
201
 
 
202
 
    static inline T_numtype apply(T_numtype1 x)
203
 
    {
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);
208
 
    }
209
 
 
210
 
    template<typename T1>
211
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
212
 
        const T1& a)
213
 
    {
214
 
        str += "pow7(";
215
 
        a.prettyPrint(str,format);
216
 
        str += ")";
217
 
    }
218
 
};
219
 
 
220
 
// pow8        Eighth power
221
 
template<typename P_numtype1>
222
 
class _bz_pow8 : public OneOperandApplicativeTemplatesBase {
223
 
public:
224
 
    typedef P_numtype1 T_numtype1;
225
 
    typedef P_numtype1 T_numtype;
226
 
 
227
 
    static inline T_numtype apply(T_numtype1 x)
228
 
    {
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);
232
 
    }
233
 
 
234
 
    template<typename T1>
235
 
    static void prettyPrint(BZ_STD_SCOPE(string) &str, prettyPrintFormat& format,
236
 
        const T1& a)
237
 
    {
238
 
        str += "pow8(";
239
 
        a.prettyPrint(str,format);
240
 
        str += ")";
241
 
    }
242
 
};
243
 
 
244
 
/*
245
 
 * These scalar versions of pow2, pow3, ..., pow8 are provided for
246
 
 * convenience.
247
 
 *
248
 
 * NEEDS_WORK -- include BZ_NO_PROPAGATE for these scalar versions.
249
 
 */
250
 
 
251
 
// NEEDS_WORK -- make these templates.  Rely on specialization to
252
 
// handle expression template versions.
253
 
 
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; }  
262
 
 
263
 
BZ_DECLARE_POW(int)
264
 
BZ_DECLARE_POW(float)
265
 
BZ_DECLARE_POW(double)
266
 
BZ_DECLARE_POW(long double)
267
 
 
268
 
#ifdef BZ_HAVE_COMPLEX
269
 
BZ_DECLARE_POW(complex<float>)
270
 
BZ_DECLARE_POW(complex<double>)
271
 
BZ_DECLARE_POW(complex<long double>)
272
 
#endif
273
 
 
274
 
BZ_NAMESPACE_END
275
 
 
276
 
#endif