OpenWalnut  1.4.0
WLimits.h
00001 //---------------------------------------------------------------------------
00002 //
00003 // Project: OpenWalnut ( http://www.openwalnut.org )
00004 //
00005 // Copyright 2009 OpenWalnut Community, BSV@Uni-Leipzig and CNCF@MPI-CBS
00006 // For more information see http://www.openwalnut.org/copying
00007 //
00008 // This file is part of OpenWalnut.
00009 //
00010 // OpenWalnut is free software: you can redistribute it and/or modify
00011 // it under the terms of the GNU Lesser General Public License as published by
00012 // the Free Software Foundation, either version 3 of the License, or
00013 // (at your option) any later version.
00014 //
00015 // OpenWalnut is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU Lesser General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU Lesser General Public License
00021 // along with OpenWalnut. If not, see <http://www.gnu.org/licenses/>.
00022 //
00023 //---------------------------------------------------------------------------
00024 
00025 #ifndef WLIMITS_H
00026 #define WLIMITS_H
00027 
00028 #include <stdint.h> // since <cstdint> is part of c++0x upcoming standard
00029 
00030 #include <cstddef>
00031 
00032 #include <boost/math/special_functions/fpclassify.hpp> // isnan, isinf
00033 
00034 /**
00035  * Project wide limits for different quantities.
00036  */
00037 namespace wlimits
00038 {
00039     extern const double MAX_DOUBLE; //!< Maximum double value
00040 
00041     extern const float MAX_FLOAT; //!< Maximum float value
00042 
00043     extern const size_t MAX_SIZE_T; //!< Maximum size value
00044 
00045     extern const int32_t MAX_INT32_T; //!< Maximum int32_t value
00046 
00047     extern const double MIN_DOUBLE; //!< Positive minimum double value
00048 
00049     /**
00050      * Smallest double such: 1.0 + DBL_EPS == 1.0 is still true.
00051      */
00052     extern const double DBL_EPS;
00053 
00054     /**
00055      * Smallest float such: 1.0 + FLT_EPS == 1.0 is still true.
00056      */
00057     extern const float FLT_EPS;
00058 
00059     /**
00060      * Determines if a number is considered as NaN (aka Not a Number) or not.
00061      *
00062      * \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.
00063      *
00064      * \param value The value to be checked
00065      *
00066      * \return True if the value is a NaN, false otherwise.
00067      */
00068     template< typename T > bool isNaN( T value );
00069 
00070     /**
00071      * Determines if a number is considered as infinity or not.
00072      *
00073      * \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.
00074      *
00075      * \param value The value to be checked
00076      *
00077      * \return True if the value is infinity, false otherwise.
00078      */
00079     template< typename T > bool isInf( T value );
00080 }
00081 
00082 template< typename T > bool wlimits::isNaN( T value )
00083 {
00084     return ( boost::math::isnan )( value );
00085 }
00086 
00087 template< typename T > bool wlimits::isInf( T value )
00088 {
00089     return ( boost::math::isinf )( value );
00090 }
00091 
00092 #endif  // WLIMITS_H