source: Sophya/trunk/SophyaExt/Blitz/blitz/numinquire.h@ 3076

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

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

File size: 6.4 KB
Line 
1/***************************************************************************
2 * blitz/numinquire.h Numeric inquiry functions
3 *
4 * $Id: numinquire.h,v 1.1.1.1 1999-04-09 17:59: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.2 1998/03/14 00:04:47 tveldhui
27 * 0.2-alpha-05
28 *
29 * Revision 1.1 1997/07/16 14:51:20 tveldhui
30 * Update: Alpha release 0.2 (Arrays)
31 *
32 */
33
34/*
35 * These numeric inquiry functions are provided as an alternative
36 * to the somewhat klunky numeric_limits<T>::yadda_yadda syntax.
37 * Where a similar Fortran 90 function exists, the same name has
38 * been used.
39 *
40 * The argument in all cases is a dummy of the appropriate type
41 * (double, int, etc.)
42 *
43 * These functions assume that numeric_limits<T> has been specialized
44 * for the appropriate case. If not, the results are not useful.
45 */
46
47#ifndef BZ_NUMINQUIRE_H
48#define BZ_NUMINQUIRE_H
49
50#ifndef BZ_HAVE_NUMERIC_LIMITS
51 #error <blitz/numinquire.h> requires <limits> from the ISO/ANSI C++ standard (you may need to rerun the compiler/bzconfig script)
52#endif
53
54#include <limits>
55
56#ifndef BZ_RANGE_H
57 #include <blitz/range.h>
58#endif
59
60BZ_NAMESPACE(blitz)
61
62/*
63 * This traits class provides zero and one values for numeric
64 * types. This was previously a template function with specializations,
65 * but the specializations were causing multiply-defined symbols
66 * at link time. TV 980226
67 */
68
69template<class T_numtype>
70struct _bz_OneZeroTraits {
71 static inline T_numtype zero() { return 0; }
72 static inline T_numtype one() { return 1; }
73};
74
75#ifdef BZ_HAVE_COMPLEX
76
77template<>
78struct _bz_OneZeroTraits<complex<float> > {
79 static inline complex<float> zero() { return complex<float>(0.0f,0.0f); }
80 static inline complex<float> one() { return complex<float>(1.0f,0.0f); }
81};
82
83template<>
84struct _bz_OneZeroTraits<complex<double> > {
85 static inline complex<double> zero() { return complex<double>(0.0,0.0); }
86 static inline complex<double> one() { return complex<double>(1.0,0.0); }
87};
88
89template<>
90struct _bz_OneZeroTraits<complex<long double> > {
91 static inline complex<long double> zero()
92 { return complex<long double>(0.0,0.0); }
93
94 static inline complex<long double> one()
95 { return complex<long double>(1.0,0.0); }
96};
97
98#endif // BZ_HAVE_COMPLEX
99
100template<class T>
101inline T zero(T)
102{
103 return _bz_OneZeroTraits<T>::zero();
104}
105
106template<class T>
107inline T one(T)
108{
109 return _bz_OneZeroTraits<T>::one();
110}
111
112template<class T>
113inline int digits(T)
114{
115 return numeric_limits<T>::digits;
116}
117
118template<class T>
119inline int digits10(T)
120{
121 return numeric_limits<T>::digits10;
122}
123
124template<class T>
125inline T epsilon(T) BZ_THROW
126{
127 return numeric_limits<T>::epsilon();
128}
129
130template<class T>
131inline T huge(T) BZ_THROW
132{
133 return numeric_limits<T>::max();
134}
135
136template<class T>
137inline T tiny(T) BZ_THROW
138{
139 return numeric_limits<T>::min();
140}
141
142template<class T>
143inline int max_exponent(T)
144{
145 return numeric_limits<T>::max_exponent;
146}
147
148template<class T>
149inline int min_exponent(T)
150{
151 return numeric_limits<T>::min_exponent;
152}
153
154template<class T>
155inline int min_exponent10(T)
156{
157 return numeric_limits<T>::min_exponent10;
158}
159
160template<class T>
161inline int max_exponent10(T)
162{
163 return numeric_limits<T>::max_exponent10;
164}
165
166template<class T>
167inline int precision(T)
168{
169 return numeric_limits<T>::digits10;
170}
171
172template<class T>
173inline int radix(T)
174{
175 return numeric_limits<T>::radix;
176}
177
178template<class T>
179inline Range range(T)
180{
181 return Range(numeric_limits<T>::min_exponent10,
182 numeric_limits<T>::max_exponent10);
183}
184
185template<class T>
186inline bool is_signed(T)
187{
188 return numeric_limits<T>::is_signed;
189}
190
191template<class T>
192inline bool is_integer(T)
193{
194 return numeric_limits<T>::is_integer;
195}
196
197template<class T>
198inline bool is_exact(T)
199{
200 return numeric_limits<T>::is_exact;
201}
202
203template<class T>
204inline T round_error(T) BZ_THROW
205{
206 return numeric_limits<T>::round_error();
207}
208
209template<class T>
210inline bool has_infinity(T)
211{
212 return numeric_limits<T>::has_infinity;
213}
214
215template<class T>
216inline bool has_quiet_NaN(T)
217{
218 return numeric_limits<T>::has_quiet_NaN;
219}
220
221template<class T>
222inline bool has_signaling_NaN(T)
223{
224 return numeric_limits<T>::has_signaling_NaN;
225}
226
227// Provided for non-US english users
228template<class T>
229inline bool has_signalling_NaN(T)
230{
231 return numeric_limits<T>::has_signaling_NaN;
232}
233
234template<class T>
235inline bool has_denorm(T)
236{
237 return numeric_limits<T>::has_denorm;
238}
239
240template<class T>
241inline bool has_denorm_loss(T)
242{
243 return numeric_limits<T>::has_denorm_loss;
244}
245
246template<class T>
247inline T infinity(T) BZ_THROW
248{
249 return numeric_limits<T>::infinity();
250}
251
252template<class T>
253inline T quiet_NaN(T) BZ_THROW
254{
255 return numeric_limits<T>::quiet_NaN();
256}
257
258template<class T>
259inline T signaling_NaN(T) BZ_THROW
260{
261 return numeric_limits<T>::signaling_NaN();
262}
263
264template<class T>
265inline T signalling_NaN(T) BZ_THROW
266{
267 return numeric_limits<T>::signaling_NaN();
268}
269
270template<class T>
271inline T denorm_min(T) BZ_THROW
272{
273 return numeric_limits<T>::denorm_min();
274}
275
276template<class T>
277inline bool is_iec559(T)
278{
279 return numeric_limits<T>::is_iec559;
280}
281
282template<class T>
283inline bool is_bounded(T)
284{
285 return numeric_limits<T>::is_bounded;
286}
287
288template<class T>
289inline bool is_modulo(T)
290{
291 return numeric_limits<T>::is_modulo;
292}
293
294template<class T>
295inline bool traps(T)
296{
297 return numeric_limits<T>::traps;
298}
299
300template<class T>
301inline bool tinyness_before(T)
302{
303 return numeric_limits<T>::tinyness_before;
304}
305
306template<class T>
307inline std::float_round_style round_style(T)
308{
309 return numeric_limits<T>::round_style;
310}
311
312BZ_NAMESPACE_END
313
314#endif // BZ_NUMINQUIRE_H
315
Note: See TracBrowser for help on using the repository browser.