1 // (C) Copyright 2007-2009 Andrew Sutton
3 // Use, modification and distribution are subject to the
4 // Boost Software License, Version 1.0 (See accompanying file
5 // LICENSE_1_0.txt or http://www.boost.org/LICENSE_1_0.txt)
7 #ifndef BOOST_GRAPH_NUMERIC_VALUES_HPP
8 #define BOOST_GRAPH_NUMERIC_VALUES_HPP
15 #define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type) \
16 template <> struct numeric_values< type > \
18 typedef type value_type; \
19 static type zero() { return 0.0; } \
20 static type infinity() \
22 return std::numeric_limits< type >::infinity(); \
27 * This generic type reports various numeric values for some type. In the
28 * general case, numeric values simply treat their maximum value as infinity
29 * and the default-constructed value as 0.
31 * Specializations of this template can redefine the notions of zero and
32 * infinity for various types. For example, the class is specialized for
33 * floating point types to use the built in notion of infinity.
35 template < typename T > struct numeric_values
39 static T zero() { return T(); }
41 static T infinity() { return (std::numeric_limits< T >::max)(); }
44 // Specializations for floating point types refer to 0.0 and their infinity
45 // value defined by numeric_limits.
46 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(float)
47 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(double)
48 BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(long double)
50 #undef BOOST_GRAPH_SPECIALIZE_NUMERIC_VALUE