00001 //---------------------------------------------------------------------------- 00002 /** @file SgUctValue.h 00003 Defines the floating point type used in SgUctSearch */ 00004 //---------------------------------------------------------------------------- 00005 00006 #ifndef SG_UCTVALUE_H 00007 #define SG_UCTVALUE_H 00008 00009 #include <cmath> 00010 #include <limits> 00011 #include <boost/static_assert.hpp> 00012 #include "SgStatistics.h" 00013 #include "SgStatisticsVlt.h" 00014 00015 //---------------------------------------------------------------------------- 00016 00017 /** @typedef SgUctValue 00018 The floating type used for mean values and counts in SgUctSearch. 00019 The default type is @c double, but it is possible to use @c float to reduce 00020 the node size and to get some performance gains (especially on 32-bit 00021 systems). However, using @c float sets a practical limit on the number of 00022 simulations before the count and mean values go into "saturation". This 00023 maximum is given by 2^d-1 with d being the digits in the mantissa (=23 for 00024 IEEE 754 float's). The search will terminate when this number is 00025 reached. */ 00026 00027 #ifdef SG_UCT_VALUE_TYPE 00028 typedef SG_UCT_VALUE_TYPE SgUctValue; 00029 #else 00030 typedef double SgUctValue; 00031 #endif 00032 00033 BOOST_STATIC_ASSERT(! std::numeric_limits<SgUctValue>::is_integer); 00034 00035 typedef SgStatisticsBase<SgUctValue,SgUctValue> SgUctStatistics; 00036 00037 typedef SgStatisticsVltBase<SgUctValue,SgUctValue> SgUctStatisticsVolatile; 00038 00039 //---------------------------------------------------------------------------- 00040 00041 namespace SgUctValueUtil 00042 { 00043 00044 /** Check if floating point value is a precise representation of an integer. 00045 When SgUctValue is used for counts, the search should abort when the 00046 value is no longer precise, because incrementing it further will not 00047 change its value anymore. 00048 @tparam T The floating point type 00049 @return @c true if value is less or equal @f$ r^d - 1 @f$ (<i>r</i>: 00050 radix, <i>d</i>: number of the digits in the mantissa of the type) */ 00051 template<typename T> 00052 inline bool IsPrecise(T val) 00053 { 00054 const int radix = std::numeric_limits<T>::radix; 00055 const int digits = std::numeric_limits<T>::digits; 00056 const T max = std::pow(T(radix), digits) - 1; 00057 return val <= max; 00058 } 00059 00060 } 00061 00062 //---------------------------------------------------------------------------- 00063 00064 #endif // SG_UCTVALUE_H