1 | /***************************************************************************
|
---|
2 | * blitz/applics.h Applicative template classes
|
---|
3 | *
|
---|
4 | * $Id: applics.h,v 1.1.1.1 1999-11-26 16:37:02 ansari Exp $
|
---|
5 | *
|
---|
6 | * Copyright (C) 1997,1998 Todd Veldhuizen <tveldhui@seurat.uwaterloo.ca>
|
---|
7 | *
|
---|
8 | * This program is free software; you can redistribute it and/or
|
---|
9 | * modify it under the terms of the GNU General Public License
|
---|
10 | * as published by the Free Software Foundation; either version 2
|
---|
11 | * of the License, or (at your option) any later version.
|
---|
12 | *
|
---|
13 | * This program is distributed in the hope that it will be useful,
|
---|
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
16 | * GNU General Public License for more details.
|
---|
17 | *
|
---|
18 | * Suggestions: blitz-suggest@cybervision.com
|
---|
19 | * Bugs: blitz-bugs@cybervision.com
|
---|
20 | *
|
---|
21 | * For more information, please see the Blitz++ Home Page:
|
---|
22 | * http://seurat.uwaterloo.ca/blitz/
|
---|
23 | *
|
---|
24 | ***************************************************************************
|
---|
25 | * $Log: not supported by cvs2svn $
|
---|
26 | * Revision 1.1.1.1 1999/04/09 17:58:58 ansari
|
---|
27 | * Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99
|
---|
28 | *
|
---|
29 | * Revision 1.5 1998/03/14 00:04:47 tveldhui
|
---|
30 | * 0.2-alpha-05
|
---|
31 | *
|
---|
32 | * Revision 1.4 1997/07/16 14:51:20 tveldhui
|
---|
33 | * Update: Alpha release 0.2 (Arrays)
|
---|
34 | *
|
---|
35 | * Revision 1.3 1997/01/24 14:42:00 tveldhui
|
---|
36 | * Periodic RCS update
|
---|
37 | *
|
---|
38 | * Revision 1.2 1997/01/13 22:19:58 tveldhui
|
---|
39 | * Periodic RCS update
|
---|
40 | *
|
---|
41 | *
|
---|
42 | */
|
---|
43 |
|
---|
44 | #ifndef BZ_APPLICS_H
|
---|
45 | #define BZ_APPLICS_H
|
---|
46 |
|
---|
47 | #ifndef BZ_BLITZ_H
|
---|
48 | #include <blitz/blitz.h>
|
---|
49 | #endif
|
---|
50 |
|
---|
51 | #ifndef BZ_PROMOTE_H
|
---|
52 | #include <blitz/promote.h>
|
---|
53 | #endif
|
---|
54 |
|
---|
55 | #ifndef BZ_NUMTRAIT_H
|
---|
56 | #include <blitz/numtrait.h>
|
---|
57 | #endif
|
---|
58 |
|
---|
59 | BZ_NAMESPACE(blitz)
|
---|
60 |
|
---|
61 | // These base classes are included for no other reason than to keep
|
---|
62 | // the applicative templates clustered together in a graphical
|
---|
63 | // class browser.
|
---|
64 | class ApplicativeTemplatesBase { };
|
---|
65 | class TwoOperandApplicativeTemplatesBase : public ApplicativeTemplatesBase { };
|
---|
66 | class OneOperandApplicativeTemplatesBase : public ApplicativeTemplatesBase { };
|
---|
67 |
|
---|
68 | template<class P_numtype1, class P_numtype2>
|
---|
69 | class _bz_Add : public TwoOperandApplicativeTemplatesBase {
|
---|
70 | public:
|
---|
71 | typedef P_numtype1 T_numtype1;
|
---|
72 | typedef P_numtype2 T_numtype2;
|
---|
73 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
74 | typedef T_promote T_numtype;
|
---|
75 |
|
---|
76 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
77 | { return x + y; }
|
---|
78 | };
|
---|
79 |
|
---|
80 | template<class P_numtype1, class P_numtype2>
|
---|
81 | class _bz_Subtract : public TwoOperandApplicativeTemplatesBase {
|
---|
82 | public:
|
---|
83 | typedef P_numtype1 T_numtype1;
|
---|
84 | typedef P_numtype2 T_numtype2;
|
---|
85 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
86 | typedef T_promote T_numtype;
|
---|
87 |
|
---|
88 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
89 | { return x - y; }
|
---|
90 | };
|
---|
91 |
|
---|
92 | template<class P_numtype1, class P_numtype2>
|
---|
93 | class _bz_Multiply : public TwoOperandApplicativeTemplatesBase {
|
---|
94 | public:
|
---|
95 | typedef P_numtype1 T_numtype1;
|
---|
96 | typedef P_numtype2 T_numtype2;
|
---|
97 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
98 | typedef T_promote T_numtype;
|
---|
99 |
|
---|
100 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
101 | { return x * y; }
|
---|
102 | };
|
---|
103 |
|
---|
104 | template<class P_numtype1, class P_numtype2>
|
---|
105 | class _bz_Divide : public TwoOperandApplicativeTemplatesBase {
|
---|
106 | public:
|
---|
107 | typedef P_numtype1 T_numtype1;
|
---|
108 | typedef P_numtype2 T_numtype2;
|
---|
109 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
110 | typedef T_promote T_numtype;
|
---|
111 |
|
---|
112 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
113 | { return x / y; }
|
---|
114 | };
|
---|
115 |
|
---|
116 | template<class P_numtype1, class P_numtype2>
|
---|
117 | class _bz_Mod : public TwoOperandApplicativeTemplatesBase {
|
---|
118 | public:
|
---|
119 | typedef P_numtype1 T_numtype1;
|
---|
120 | typedef P_numtype2 T_numtype2;
|
---|
121 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
122 | typedef T_promote T_numtype;
|
---|
123 |
|
---|
124 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
125 | { return x % y; }
|
---|
126 | };
|
---|
127 |
|
---|
128 | template<class P_numtype1, class P_numtype2>
|
---|
129 | class _bz_BitwiseXOR : public TwoOperandApplicativeTemplatesBase {
|
---|
130 | public:
|
---|
131 | typedef P_numtype1 T_numtype1;
|
---|
132 | typedef P_numtype2 T_numtype2;
|
---|
133 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
134 | typedef T_promote T_numtype;
|
---|
135 |
|
---|
136 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
137 | { return x ^ y; }
|
---|
138 | };
|
---|
139 |
|
---|
140 | template<class P_numtype1, class P_numtype2>
|
---|
141 | class _bz_BitwiseAnd : public TwoOperandApplicativeTemplatesBase {
|
---|
142 | public:
|
---|
143 | typedef P_numtype1 T_numtype1;
|
---|
144 | typedef P_numtype2 T_numtype2;
|
---|
145 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
146 | typedef T_promote T_numtype;
|
---|
147 |
|
---|
148 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
149 | { return x & y; }
|
---|
150 | };
|
---|
151 |
|
---|
152 | template<class P_numtype1, class P_numtype2>
|
---|
153 | class _bz_BitwiseOr : public TwoOperandApplicativeTemplatesBase {
|
---|
154 | public:
|
---|
155 | typedef P_numtype1 T_numtype1;
|
---|
156 | typedef P_numtype2 T_numtype2;
|
---|
157 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
158 | typedef T_promote T_numtype;
|
---|
159 |
|
---|
160 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
161 | { return x | y; }
|
---|
162 | };
|
---|
163 |
|
---|
164 | template<class P_numtype1, class P_numtype2>
|
---|
165 | class _bz_ShiftRight : public TwoOperandApplicativeTemplatesBase {
|
---|
166 | public:
|
---|
167 | typedef P_numtype1 T_numtype1;
|
---|
168 | typedef P_numtype2 T_numtype2;
|
---|
169 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
170 | typedef T_promote T_numtype;
|
---|
171 |
|
---|
172 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
173 | { return x >> y; }
|
---|
174 | };
|
---|
175 |
|
---|
176 | template<class P_numtype1, class P_numtype2>
|
---|
177 | class _bz_ShiftLeft : public TwoOperandApplicativeTemplatesBase {
|
---|
178 | public:
|
---|
179 | typedef P_numtype1 T_numtype1;
|
---|
180 | typedef P_numtype2 T_numtype2;
|
---|
181 | typedef BZ_PROMOTE(T_numtype1,T_numtype2) T_promote;
|
---|
182 | typedef T_promote T_numtype;
|
---|
183 |
|
---|
184 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
185 | { return x << y; }
|
---|
186 | };
|
---|
187 |
|
---|
188 | template<class P_numtype1, class P_numtype2>
|
---|
189 | class _bz_Greater : public TwoOperandApplicativeTemplatesBase {
|
---|
190 | public:
|
---|
191 | typedef P_numtype1 T_numtype1;
|
---|
192 | typedef P_numtype2 T_numtype2;
|
---|
193 | typedef _bz_bool T_promote;
|
---|
194 | typedef T_promote T_numtype;
|
---|
195 |
|
---|
196 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
197 | { return x > y; }
|
---|
198 | };
|
---|
199 |
|
---|
200 | template<class P_numtype1, class P_numtype2>
|
---|
201 | class _bz_Less : public TwoOperandApplicativeTemplatesBase {
|
---|
202 | public:
|
---|
203 | typedef P_numtype1 T_numtype1;
|
---|
204 | typedef P_numtype2 T_numtype2;
|
---|
205 | typedef _bz_bool T_promote;
|
---|
206 | typedef T_promote T_numtype;
|
---|
207 |
|
---|
208 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
209 | { return x < y; }
|
---|
210 | };
|
---|
211 |
|
---|
212 | template<class P_numtype1, class P_numtype2>
|
---|
213 | class _bz_GreaterOrEqual : public TwoOperandApplicativeTemplatesBase {
|
---|
214 | public:
|
---|
215 | typedef P_numtype1 T_numtype1;
|
---|
216 | typedef P_numtype2 T_numtype2;
|
---|
217 | typedef _bz_bool T_promote;
|
---|
218 | typedef T_promote T_numtype;
|
---|
219 |
|
---|
220 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
221 | { return x >= y; }
|
---|
222 | };
|
---|
223 |
|
---|
224 | template<class P_numtype1, class P_numtype2>
|
---|
225 | class _bz_LessOrEqual : public TwoOperandApplicativeTemplatesBase {
|
---|
226 | public:
|
---|
227 | typedef P_numtype1 T_numtype1;
|
---|
228 | typedef P_numtype2 T_numtype2;
|
---|
229 | typedef _bz_bool T_promote;
|
---|
230 | typedef T_promote T_numtype;
|
---|
231 |
|
---|
232 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
233 | { return x <= y; }
|
---|
234 | };
|
---|
235 |
|
---|
236 | template<class P_numtype1, class P_numtype2>
|
---|
237 | class _bz_Equal : public TwoOperandApplicativeTemplatesBase {
|
---|
238 | public:
|
---|
239 | typedef P_numtype1 T_numtype1;
|
---|
240 | typedef P_numtype2 T_numtype2;
|
---|
241 | typedef _bz_bool T_promote;
|
---|
242 | typedef T_promote T_numtype;
|
---|
243 |
|
---|
244 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
245 | { return x == y; }
|
---|
246 | };
|
---|
247 |
|
---|
248 | template<class P_numtype1, class P_numtype2>
|
---|
249 | class _bz_NotEqual : public TwoOperandApplicativeTemplatesBase {
|
---|
250 | public:
|
---|
251 | typedef P_numtype1 T_numtype1;
|
---|
252 | typedef P_numtype2 T_numtype2;
|
---|
253 | typedef _bz_bool T_promote;
|
---|
254 | typedef T_promote T_numtype;
|
---|
255 |
|
---|
256 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
257 | { return x != y; }
|
---|
258 | };
|
---|
259 |
|
---|
260 | template<class P_numtype1, class P_numtype2>
|
---|
261 | class _bz_LogicalAnd : public TwoOperandApplicativeTemplatesBase {
|
---|
262 | public:
|
---|
263 | typedef P_numtype1 T_numtype1;
|
---|
264 | typedef P_numtype2 T_numtype2;
|
---|
265 | typedef _bz_bool T_promote;
|
---|
266 | typedef T_promote T_numtype;
|
---|
267 |
|
---|
268 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
269 | { return x && y; }
|
---|
270 | };
|
---|
271 |
|
---|
272 | template<class P_numtype1, class P_numtype2>
|
---|
273 | class _bz_LogicalOr : public TwoOperandApplicativeTemplatesBase {
|
---|
274 | public:
|
---|
275 | typedef P_numtype1 T_numtype1;
|
---|
276 | typedef P_numtype2 T_numtype2;
|
---|
277 | typedef _bz_bool T_promote;
|
---|
278 | typedef T_promote T_numtype;
|
---|
279 |
|
---|
280 | static inline T_promote apply(P_numtype1 x, P_numtype2 y)
|
---|
281 | { return x || y; }
|
---|
282 | };
|
---|
283 |
|
---|
284 | template<class P_numtype_in, class P_numtype_out>
|
---|
285 | class _bz_Cast : public OneOperandApplicativeTemplatesBase {
|
---|
286 | public:
|
---|
287 | typedef P_numtype_in T_numtype1;
|
---|
288 | typedef P_numtype_out T_promote;
|
---|
289 | typedef T_promote T_numtype;
|
---|
290 |
|
---|
291 | static inline P_numtype_out apply(P_numtype_in x)
|
---|
292 | { return P_numtype_out(x); }
|
---|
293 | };
|
---|
294 |
|
---|
295 | template<class P_numtype>
|
---|
296 | class _bz_LogicalNot : public OneOperandApplicativeTemplatesBase {
|
---|
297 | public:
|
---|
298 | typedef P_numtype T_numtype1;
|
---|
299 | typedef _bz_bool T_promote;
|
---|
300 | typedef T_promote T_numtype;
|
---|
301 |
|
---|
302 | static inline P_numtype apply(P_numtype x)
|
---|
303 | { return !x; }
|
---|
304 | };
|
---|
305 |
|
---|
306 | template<class P_numtype>
|
---|
307 | class _bz_BitwiseNot : public OneOperandApplicativeTemplatesBase {
|
---|
308 | public:
|
---|
309 | typedef P_numtype T_numtype1;
|
---|
310 | typedef T_numtype1 T_promote;
|
---|
311 | typedef T_promote T_numtype;
|
---|
312 |
|
---|
313 | static inline P_numtype apply(P_numtype x)
|
---|
314 | { return ~x; }
|
---|
315 | };
|
---|
316 |
|
---|
317 | /*****************************************************************************
|
---|
318 | * Math Functions
|
---|
319 | *****************************************************************************/
|
---|
320 |
|
---|
321 | // Applicative templates for these functions are defined in
|
---|
322 | // <blitz/mathfunc.h>, which is included below:
|
---|
323 | //
|
---|
324 | // abs(i), labs(l) Absolute value
|
---|
325 | // acos(d), acols(ld) Inverse cosine
|
---|
326 | // acosh(d) Inverse hyperbolic cosine
|
---|
327 | // asin(d), asinl(ld) Inverse sine
|
---|
328 | // asinh(d) Inverse hyperbolic sine
|
---|
329 | // atan(d), atanl(ld) Inverse tangent
|
---|
330 | // atan2(d,d), atan2l(ld,ld) Inverse tangent
|
---|
331 | // atanh(d) Inverse hyperbolic tangent
|
---|
332 | // cbrt(x) Cube root
|
---|
333 | // ceil(d), ceill(ld) Smallest f-int not less than x
|
---|
334 | // int class(d) Classification of x (FP_XXXXX)
|
---|
335 | // cos(d), cosl(ld) Cosine
|
---|
336 | // cosh(d), coshl(ld) Hyperbolic cosine
|
---|
337 | // copysign(d,d) Return 1st arg with same sign as 2nd
|
---|
338 | // drem(x,x) IEEE remainder
|
---|
339 | // exp(d), expl(ld) Exponential
|
---|
340 | // expm1(d) Exp(x)-1
|
---|
341 | // erf(d), erfl(ld) Error function
|
---|
342 | // erfc(d), erfcl(ld) Complementary error function
|
---|
343 | // fabs(d), fabsl(ld) Floating point absolute value
|
---|
344 | // int finite(d) Nonzero if finite
|
---|
345 | // floor(d), floor(ld) Largest f-int not greater than x
|
---|
346 | // fmod(d,d), fmodl(ld,ld) Floating point remainder
|
---|
347 | // frexp(d, int* e) Break into mantissa/exponent (*)
|
---|
348 | // frexpl(ld, int* e) Break into mantissa/exponent (*)
|
---|
349 | // gammaFunc(d) Gamma function (** needs special
|
---|
350 | // implementation using lgamma)
|
---|
351 | // hypot(d,d) Hypotenuse: sqrt(x*x+y*y)
|
---|
352 | // int ilogb(d) Integer unbiased exponent
|
---|
353 | // int isnan(d) Nonzero if NaNS or NaNQ
|
---|
354 | // int itrunc(d) Truncate and convert to integer
|
---|
355 | // j0(d) Bessel function first kind, order 0
|
---|
356 | // j1(d) Bessel function first kind, order 1
|
---|
357 | // jn(int, double) Bessel function first kind, order i
|
---|
358 | // ldexp(d,i), ldexpl(ld,i) Compute d * 2^i
|
---|
359 | // lgamma(d), lgammald(ld) Log absolute gamma
|
---|
360 | // log(d), logl(ld) Natural logarithm
|
---|
361 | // logb(d) Unbiased exponent (IEEE)
|
---|
362 | // log1p(d) Compute log(1 + x)
|
---|
363 | // log10(d), log10l(ld) Logarithm base 10
|
---|
364 | // modf(d, int* i), modfl(ld, int* i) Break into integral/fractional part
|
---|
365 | // double nearest(double) Nearest floating point integer
|
---|
366 | // nextafter(d, d) Next representable neighbor of 1st
|
---|
367 | // in direction of 2nd
|
---|
368 | // pow(d,d), pow(ld,ld) Computes x ^ y
|
---|
369 | // d remainder(d,d) IEEE remainder
|
---|
370 | // d rint(d) Round to f-integer (depends on mode)
|
---|
371 | // d rsqrt(d) Reciprocal square root
|
---|
372 | // d scalb(d,d) Return x * (2^y)
|
---|
373 | // sin(d), sinl(ld) Sine
|
---|
374 | // sinh(d), sinhl(ld) Hyperbolic sine
|
---|
375 | // sqr(x) Return x * x
|
---|
376 | // sqrt(d), sqrtl(ld) Square root
|
---|
377 | // tan(d), tanl(ld) Tangent
|
---|
378 | // tanh(d), tanhl(ld) Hyperbolic tangent
|
---|
379 | // trunc(d) Nearest f-int in the direction of 0
|
---|
380 | // unsigned uitrunc(d) Truncate and convert to unsigned
|
---|
381 | // int unordered(d,d) Nonzero if comparison is unordered
|
---|
382 | // y0(d) Bessel function 2nd kind, order 0
|
---|
383 | // y1(d) Bessel function 2nd kind, order 1
|
---|
384 | // yn(i,d) Bessel function 2nd kind, order d
|
---|
385 |
|
---|
386 |
|
---|
387 | BZ_NAMESPACE_END
|
---|
388 |
|
---|
389 | #ifndef BZ_MATHFUNC_H
|
---|
390 | #include <blitz/mathfunc.h>
|
---|
391 | #endif
|
---|
392 |
|
---|
393 | #ifndef BZ_MATHF2_H
|
---|
394 | #include <blitz/mathf2.h>
|
---|
395 | #endif
|
---|
396 |
|
---|
397 | #endif // BZ_APPLICS_H
|
---|