• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // (C) Copyright 2007-2009 Andrew Sutton
2 //
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)
6 
7 #ifndef BOOST_GRAPH_NUMERIC_VALUES_HPP
8 #define BOOST_GRAPH_NUMERIC_VALUES_HPP
9 
10 #include <limits>
11 
12 namespace boost
13 {
14 
15 #define BOOST_GRAPH_SPECIALIZE_NUMERIC_FLOAT(type)          \
16     template <> struct numeric_values< type >               \
17     {                                                       \
18         typedef type value_type;                            \
19         static type zero() { return 0.0; }                  \
20         static type infinity()                              \
21         {                                                   \
22             return std::numeric_limits< type >::infinity(); \
23         }                                                   \
24     };
25 
26 /**
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.
30  *
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.
34  */
35 template < typename T > struct numeric_values
36 {
37     typedef T value_type;
38 
zeroboost::numeric_values39     static T zero() { return T(); }
40 
infinityboost::numeric_values41     static T infinity() { return (std::numeric_limits< T >::max)(); }
42 };
43 
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)
49 
50 #undef BOOST_GRAPH_SPECIALIZE_NUMERIC_VALUE
51 }
52 
53 #endif
54