Added the function isFinite(), and replaced the calls to finite() with it.
authorladanyi
Sat, 13 Oct 2007 08:48:07 +0000
changeset 2495e4f8367beb41
parent 2494 839c74eeba84
child 2496 72c3c25d5b8f
Added the function isFinite(), and replaced the calls to finite() with it.
This was necessary because finite() is not a standard function. Neither can
we use its standard counterpart isfinite(), because it was introduced only
in C99, and therefore it is not supplied by all C++ implementations.
lemon/lp_base.h
     1.1 --- a/lemon/lp_base.h	Fri Oct 12 22:19:03 2007 +0000
     1.2 +++ b/lemon/lp_base.h	Sat Oct 13 08:48:07 2007 +0000
     1.3 @@ -35,6 +35,23 @@
     1.4  ///\ingroup lp_group
     1.5  namespace lemon {
     1.6  
     1.7 +  /// Function to decide whether a floating point value is finite or not.
     1.8 +
     1.9 +  /// Retruns true if the argument is not infinity, minus infinity or NaN.
    1.10 +  /// It does the same as the isfinite() function defined by C99.
    1.11 +  template <typename T>
    1.12 +  bool isFinite(T value)
    1.13 +  {
    1.14 +    typedef std::numeric_limits<T> Lim;
    1.15 +    if (Lim::has_infinity && (value == Lim::infinity() || value ==
    1.16 +          -Lim::infinity()) ||
    1.17 +        (Lim::has_quiet_NaN || Lim::has_signaling_NaN) && value != value)
    1.18 +    {
    1.19 +      return false;
    1.20 +    }
    1.21 +    return true;
    1.22 +  }
    1.23 +
    1.24    ///Common base class for LP solvers
    1.25    
    1.26    ///\todo Much more docs
    1.27 @@ -457,13 +474,11 @@
    1.28        const Value &upperBound() const { return _ub; }
    1.29        ///Is the constraint lower bounded?
    1.30        bool lowerBounded() const { 
    1.31 -	using namespace std;
    1.32 -	return finite(_lb);
    1.33 +	return isFinite(_lb);
    1.34        }
    1.35        ///Is the constraint upper bounded?
    1.36        bool upperBounded() const {
    1.37 -	using namespace std;
    1.38 -	return finite(_ub);
    1.39 +	return isFinite(_ub);
    1.40        }
    1.41  
    1.42        void prettyPrint(std::ostream &os) {