00001 #ifndef SGE_MATH_DIFF_HPP_INCLUDED
00002 #define SGE_MATH_DIFF_HPP_INCLUDED
00003
00004 #include <boost/utility/enable_if.hpp>
00005 #include <boost/type_traits/is_unsigned.hpp>
00006 #include <algorithm>
00007 #include <cmath>
00008 #include <cstdlib>
00009
00010 namespace sge
00011 {
00012 namespace math
00013 {
00014
00015 template<typename T>
00016 inline typename boost::disable_if<boost::is_unsigned<T>, T>::type
00017 diff(T const &a, T const &b)
00018 {
00019 return std::abs(a - b);
00020 }
00021
00022 template<typename T>
00023 inline typename boost::enable_if<boost::is_unsigned<T>, T>::type
00024 diff(T const& a, T const &b)
00025 {
00026 return std::min(a - b, b - a);
00027 }
00028
00029 }
00030 }
00031
00032 #endif