OpenWalnut  1.2.5
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
WLimits.h
1 //---------------------------------------------------------------------------
2 //
3 // Project: OpenWalnut ( http://www.openwalnut.org )
4 //
5 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
6 // For more information see http://www.openwalnut.org/copying
7 //
8 // This file is part of OpenWalnut.
9 //
10 // OpenWalnut is free software: you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // OpenWalnut is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU Lesser General Public License for more details.
19 //
20 // You should have received a copy of the GNU Lesser General Public License
21 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
22 //
23 //---------------------------------------------------------------------------
24 
25 #ifndef WLIMITS_H
26 #define WLIMITS_H
27 
28 #include <stdint.h> // since <cstdint> is part of c++0x upcoming standard
29 
30 #include <cstddef>
31 #include <limits>
32 
33 #include <boost/math/special_functions/fpclassify.hpp> // isnan, isinf
34 
35 /**
36  * Project wide limits for different quantitities.
37  */
38 namespace wlimits
39 {
40  static const double MAX_DOUBLE = std::numeric_limits< double >::max(); //!< Maximum double value
41 
42  static const float MAX_FLOAT = std::numeric_limits< float >::max(); //!< Maximum float value
43 
44  static const size_t MAX_SIZE_T = std::numeric_limits< size_t >::max(); //!< Maximum size value
45 
46  static const int32_t MAX_INT32_T = std::numeric_limits< int32_t >::max(); //!< Maximum int32_t value
47 
48  static const double MIN_DOUBLE = std::numeric_limits< double >::min(); //!< Positive minimum double value
49 
50  /**
51  * Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.
52  */
53  static const double DBL_EPS = std::numeric_limits< double >::epsilon();
54 
55  /**
56  * Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
57  */
58  static const float FLT_EPS = std::numeric_limits< float >::epsilon();
59 
60  /**
61  * Determines if a number is considered as NaN (aka Not a Number) or not.
62  *
63  * \note The reason for using here a wrapper to cmath's isnan is that it is only included in C99 which is not part of any existing C++ standard yet.
64  *
65  * \param value The value to be checked
66  *
67  * \return True if the value is a NaN, false otherwise.
68  */
69  template< typename T > bool isnan( T value );
70 
71  /**
72  * Determines if a number is considered as infinity or not.
73  *
74  * \note The reason for using here a wrapper to cmath's isinf is that it is only included in C99 which is not part of any existing C++ standard yet.
75  *
76  * \param value The value to be checked
77  *
78  * \return True if the value is infinity, false otherwise.
79  */
80  template< typename T > bool isinf( T value );
81 }
82 
83 template< typename T > bool wlimits::isnan( T value )
84 {
85  return boost::math::isnan( value );
86 }
87 
88 template< typename T > bool wlimits::isinf( T value )
89 {
90  return boost::math::isinf( value );
91 }
92 
93 #endif // WLIMITS_H