| 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 | 
 | 
|---|
| 60 | BZ_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 | 
 | 
|---|
| 69 | template<class T_numtype>
 | 
|---|
| 70 | struct _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 | 
 | 
|---|
| 77 | template<>
 | 
|---|
| 78 | struct _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 | 
 | 
|---|
| 83 | template<>
 | 
|---|
| 84 | struct _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 | 
 | 
|---|
| 89 | template<>
 | 
|---|
| 90 | struct _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 | 
 | 
|---|
| 100 | template<class T>
 | 
|---|
| 101 | inline T zero(T)
 | 
|---|
| 102 | {
 | 
|---|
| 103 |     return _bz_OneZeroTraits<T>::zero();
 | 
|---|
| 104 | }
 | 
|---|
| 105 | 
 | 
|---|
| 106 | template<class T>
 | 
|---|
| 107 | inline T one(T)
 | 
|---|
| 108 | {
 | 
|---|
| 109 |     return _bz_OneZeroTraits<T>::one();
 | 
|---|
| 110 | }
 | 
|---|
| 111 | 
 | 
|---|
| 112 | template<class T>
 | 
|---|
| 113 | inline int digits(T)
 | 
|---|
| 114 | {
 | 
|---|
| 115 |     return numeric_limits<T>::digits;
 | 
|---|
| 116 | }
 | 
|---|
| 117 | 
 | 
|---|
| 118 | template<class T>
 | 
|---|
| 119 | inline int digits10(T)
 | 
|---|
| 120 | {
 | 
|---|
| 121 |     return numeric_limits<T>::digits10;
 | 
|---|
| 122 | }
 | 
|---|
| 123 | 
 | 
|---|
| 124 | template<class T>
 | 
|---|
| 125 | inline T epsilon(T) BZ_THROW
 | 
|---|
| 126 | {
 | 
|---|
| 127 |     return numeric_limits<T>::epsilon();
 | 
|---|
| 128 | }
 | 
|---|
| 129 | 
 | 
|---|
| 130 | template<class T>
 | 
|---|
| 131 | inline T huge(T) BZ_THROW
 | 
|---|
| 132 | {
 | 
|---|
| 133 |     return numeric_limits<T>::max();
 | 
|---|
| 134 | }
 | 
|---|
| 135 | 
 | 
|---|
| 136 | template<class T>
 | 
|---|
| 137 | inline T tiny(T) BZ_THROW
 | 
|---|
| 138 | {
 | 
|---|
| 139 |     return numeric_limits<T>::min();
 | 
|---|
| 140 | }
 | 
|---|
| 141 | 
 | 
|---|
| 142 | template<class T>
 | 
|---|
| 143 | inline int max_exponent(T)
 | 
|---|
| 144 | {
 | 
|---|
| 145 |     return numeric_limits<T>::max_exponent;
 | 
|---|
| 146 | }
 | 
|---|
| 147 | 
 | 
|---|
| 148 | template<class T>
 | 
|---|
| 149 | inline int min_exponent(T)
 | 
|---|
| 150 | {
 | 
|---|
| 151 |     return numeric_limits<T>::min_exponent;
 | 
|---|
| 152 | }
 | 
|---|
| 153 | 
 | 
|---|
| 154 | template<class T>
 | 
|---|
| 155 | inline int min_exponent10(T)
 | 
|---|
| 156 | {
 | 
|---|
| 157 |     return numeric_limits<T>::min_exponent10;
 | 
|---|
| 158 | }
 | 
|---|
| 159 | 
 | 
|---|
| 160 | template<class T>
 | 
|---|
| 161 | inline int max_exponent10(T)
 | 
|---|
| 162 | {
 | 
|---|
| 163 |     return numeric_limits<T>::max_exponent10;
 | 
|---|
| 164 | }
 | 
|---|
| 165 | 
 | 
|---|
| 166 | template<class T>
 | 
|---|
| 167 | inline int precision(T)
 | 
|---|
| 168 | {
 | 
|---|
| 169 |     return numeric_limits<T>::digits10;
 | 
|---|
| 170 | }
 | 
|---|
| 171 | 
 | 
|---|
| 172 | template<class T>
 | 
|---|
| 173 | inline int radix(T)
 | 
|---|
| 174 | {
 | 
|---|
| 175 |     return numeric_limits<T>::radix;
 | 
|---|
| 176 | }
 | 
|---|
| 177 | 
 | 
|---|
| 178 | template<class T>
 | 
|---|
| 179 | inline Range range(T)
 | 
|---|
| 180 | {
 | 
|---|
| 181 |     return Range(numeric_limits<T>::min_exponent10, 
 | 
|---|
| 182 |         numeric_limits<T>::max_exponent10);
 | 
|---|
| 183 | }
 | 
|---|
| 184 | 
 | 
|---|
| 185 | template<class T>
 | 
|---|
| 186 | inline bool is_signed(T)
 | 
|---|
| 187 | {
 | 
|---|
| 188 |     return numeric_limits<T>::is_signed;
 | 
|---|
| 189 | }
 | 
|---|
| 190 | 
 | 
|---|
| 191 | template<class T>
 | 
|---|
| 192 | inline bool is_integer(T)
 | 
|---|
| 193 | {
 | 
|---|
| 194 |     return numeric_limits<T>::is_integer;
 | 
|---|
| 195 | }
 | 
|---|
| 196 | 
 | 
|---|
| 197 | template<class T>
 | 
|---|
| 198 | inline bool is_exact(T)
 | 
|---|
| 199 | {
 | 
|---|
| 200 |     return numeric_limits<T>::is_exact;
 | 
|---|
| 201 | }
 | 
|---|
| 202 | 
 | 
|---|
| 203 | template<class T>
 | 
|---|
| 204 | inline T round_error(T) BZ_THROW
 | 
|---|
| 205 | {
 | 
|---|
| 206 |     return numeric_limits<T>::round_error();
 | 
|---|
| 207 | }
 | 
|---|
| 208 | 
 | 
|---|
| 209 | template<class T>
 | 
|---|
| 210 | inline bool has_infinity(T) 
 | 
|---|
| 211 | {
 | 
|---|
| 212 |     return numeric_limits<T>::has_infinity;
 | 
|---|
| 213 | }
 | 
|---|
| 214 | 
 | 
|---|
| 215 | template<class T>
 | 
|---|
| 216 | inline bool has_quiet_NaN(T)
 | 
|---|
| 217 | {
 | 
|---|
| 218 |     return numeric_limits<T>::has_quiet_NaN;
 | 
|---|
| 219 | }
 | 
|---|
| 220 | 
 | 
|---|
| 221 | template<class T>
 | 
|---|
| 222 | inline bool has_signaling_NaN(T)
 | 
|---|
| 223 | {
 | 
|---|
| 224 |     return numeric_limits<T>::has_signaling_NaN;
 | 
|---|
| 225 | }
 | 
|---|
| 226 | 
 | 
|---|
| 227 | // Provided for non-US english users
 | 
|---|
| 228 | template<class T>
 | 
|---|
| 229 | inline bool has_signalling_NaN(T)
 | 
|---|
| 230 | {
 | 
|---|
| 231 |     return numeric_limits<T>::has_signaling_NaN;
 | 
|---|
| 232 | }
 | 
|---|
| 233 | 
 | 
|---|
| 234 | template<class T>
 | 
|---|
| 235 | inline bool has_denorm(T)
 | 
|---|
| 236 | {
 | 
|---|
| 237 |     return numeric_limits<T>::has_denorm;
 | 
|---|
| 238 | }
 | 
|---|
| 239 | 
 | 
|---|
| 240 | template<class T>
 | 
|---|
| 241 | inline bool has_denorm_loss(T)
 | 
|---|
| 242 | {
 | 
|---|
| 243 |     return numeric_limits<T>::has_denorm_loss;
 | 
|---|
| 244 | }
 | 
|---|
| 245 | 
 | 
|---|
| 246 | template<class T>
 | 
|---|
| 247 | inline T infinity(T) BZ_THROW
 | 
|---|
| 248 | {
 | 
|---|
| 249 |     return numeric_limits<T>::infinity();
 | 
|---|
| 250 | }
 | 
|---|
| 251 | 
 | 
|---|
| 252 | template<class T>
 | 
|---|
| 253 | inline T quiet_NaN(T) BZ_THROW
 | 
|---|
| 254 | {
 | 
|---|
| 255 |     return numeric_limits<T>::quiet_NaN();
 | 
|---|
| 256 | }
 | 
|---|
| 257 | 
 | 
|---|
| 258 | template<class T>
 | 
|---|
| 259 | inline T signaling_NaN(T) BZ_THROW
 | 
|---|
| 260 | {
 | 
|---|
| 261 |     return numeric_limits<T>::signaling_NaN();
 | 
|---|
| 262 | }
 | 
|---|
| 263 | 
 | 
|---|
| 264 | template<class T>
 | 
|---|
| 265 | inline T signalling_NaN(T) BZ_THROW
 | 
|---|
| 266 | {
 | 
|---|
| 267 |     return numeric_limits<T>::signaling_NaN();
 | 
|---|
| 268 | }
 | 
|---|
| 269 | 
 | 
|---|
| 270 | template<class T>
 | 
|---|
| 271 | inline T denorm_min(T) BZ_THROW
 | 
|---|
| 272 | {
 | 
|---|
| 273 |     return numeric_limits<T>::denorm_min();
 | 
|---|
| 274 | }
 | 
|---|
| 275 | 
 | 
|---|
| 276 | template<class T>
 | 
|---|
| 277 | inline bool is_iec559(T)
 | 
|---|
| 278 | {
 | 
|---|
| 279 |     return numeric_limits<T>::is_iec559;
 | 
|---|
| 280 | }
 | 
|---|
| 281 | 
 | 
|---|
| 282 | template<class T>
 | 
|---|
| 283 | inline bool is_bounded(T)
 | 
|---|
| 284 | {
 | 
|---|
| 285 |     return numeric_limits<T>::is_bounded;
 | 
|---|
| 286 | }
 | 
|---|
| 287 | 
 | 
|---|
| 288 | template<class T>
 | 
|---|
| 289 | inline bool is_modulo(T)
 | 
|---|
| 290 | {
 | 
|---|
| 291 |     return numeric_limits<T>::is_modulo;
 | 
|---|
| 292 | }
 | 
|---|
| 293 | 
 | 
|---|
| 294 | template<class T>
 | 
|---|
| 295 | inline bool traps(T)
 | 
|---|
| 296 | {
 | 
|---|
| 297 |     return numeric_limits<T>::traps;
 | 
|---|
| 298 | }
 | 
|---|
| 299 | 
 | 
|---|
| 300 | template<class T>
 | 
|---|
| 301 | inline bool tinyness_before(T)
 | 
|---|
| 302 | {
 | 
|---|
| 303 |     return numeric_limits<T>::tinyness_before;
 | 
|---|
| 304 | }
 | 
|---|
| 305 | 
 | 
|---|
| 306 | template<class T>
 | 
|---|
| 307 | inline std::float_round_style round_style(T)
 | 
|---|
| 308 | {
 | 
|---|
| 309 |     return numeric_limits<T>::round_style;
 | 
|---|
| 310 | }
 | 
|---|
| 311 | 
 | 
|---|
| 312 | BZ_NAMESPACE_END
 | 
|---|
| 313 | 
 | 
|---|
| 314 | #endif // BZ_NUMINQUIRE_H
 | 
|---|
| 315 | 
 | 
|---|