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