source: XMLIO_V2/external/include/blitz/numinquire.h @ 73

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