source: Sophya/trunk/SophyaExt/Blitz/blitz/applics.h@ 4023

Last change on this file since 4023 was 221, checked in by ansari, 26 years ago

Creation module DPC/Blitz (blitz 0.4) Reza 09/04/99

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