source: XIOS/dev/dev_olga/src/extern/blitz/include/blitz/numinquire.h @ 1022

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