CoinUtils trunk
CoinFinite.hpp
Go to the documentation of this file.
00001 /* $Id$ */
00002 // Copyright (C) 2002, International Business Machines
00003 // Corporation and others.  All Rights Reserved.
00004 // This code is licensed under the terms of the Eclipse Public License (EPL).
00005 
00006 /* Defines COIN_DBL_MAX and relatives and provides CoinFinite and CoinIsnan.
00007  * NOTE: If used outside of CoinUtils, it is assumed that the HAVE_CFLOAT, HAVE_CMATH, and HAVE_CIEEEFP symbols have been defined,
00008  * so DBL_MAX and the functions behind COIN_C_FINITE and COIN_C_ISNAN are defined.
00009  * The reason is that the public config header file of CoinUtils does not define these symbols anymore, since it does not know on
00010  * which system the library will be used.
00011  *
00012  * As a consequence, it is suggested to include this header only in .c/.cpp files, but not in header files,
00013  * since this introduces the same assumptions to these headers and everyone using them.
00014  */
00015 
00016 #ifndef CoinFinite_H
00017 #define CoinFinite_H
00018 
00019 #include "CoinUtilsConfig.h"
00020 
00021 #ifdef HAVE_CFLOAT
00022 # include <cfloat>
00023 #else
00024 # ifdef HAVE_FLOAT_H
00025 #  include <float.h>
00026 # endif
00027 #endif
00028 
00029 #ifdef HAVE_CMATH
00030 # include <cmath>
00031 #else
00032 # ifdef HAVE_MATH_H
00033 #  include <math.h>
00034 # endif
00035 #endif
00036 
00037 #ifdef HAVE_CIEEEFP
00038 # include <cieeefp>
00039 #else
00040 # ifdef HAVE_IEEEFP_H
00041 #  include <ieeefp.h>
00042 # endif
00043 #endif
00044 
00045 //=============================================================================
00046 // Plus infinity (double and int)
00047 #ifndef COIN_DBL_MAX
00048 #ifndef DBL_MAX
00049 #warning "Using COIN_DBL_MAX may fail since DBL_MAX is not defined. Probably your projects XyzConfig.h need to be included before CoinFinite.hpp."
00050 #endif
00051 #define COIN_DBL_MAX DBL_MAX
00052 #endif
00053 
00054 #ifndef COIN_INT_MAX
00055 #define COIN_INT_MAX (static_cast<int>((~(static_cast<unsigned int>(0))) >> 1))
00056 #endif
00057 
00058 #ifndef COIN_INT_MAX_AS_DOUBLE
00059 #define COIN_INT_MAX_AS_DOUBLE (static_cast<double>((~(static_cast<unsigned int>(0))) >> 1))
00060 #endif
00061 
00062 inline bool CoinFinite(double val)
00063 {
00064 #ifdef COIN_C_FINITE
00065     return COIN_C_FINITE(val)!=0;
00066 #else
00067     return val != DBL_MAX && val != -DBL_MAX;
00068 #endif
00069 }
00070 
00071 inline bool CoinIsnan(double val)
00072 {
00073 #ifdef COIN_C_ISNAN
00074     return COIN_C_ISNAN(val)!=0;
00075 #else
00076     return false;
00077 #endif
00078 }
00079 
00080 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines