00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SGE_MATH_MOD_HPP_INCLUDED
00021 #define SGE_MATH_MOD_HPP_INCLUDED
00022
00023 #include <cmath>
00024 #include <boost/utility/enable_if.hpp>
00025 #include <boost/type_traits/is_unsigned.hpp>
00026 #include <boost/type_traits/is_floating_point.hpp>
00027
00028 namespace sge
00029 {
00030 namespace math
00031 {
00032 template<typename T>
00033 typename boost::enable_if<boost::is_floating_point<T>, void>::type mod_assign(T& l, const T& r)
00034 {
00035 l = std::fmod(l, r);
00036 }
00037
00038 template<typename T>
00039 typename boost::enable_if<boost::is_unsigned<T>, void>::type mod_assign(T& l, const T& r)
00040 {
00041 l %= r;
00042 }
00043
00044 template<typename T>
00045 typename boost::enable_if<boost::is_floating_point<T>, T>::type mod(const T& a, const T& b)
00046 {
00047 return std::fmod(a, b);
00048 }
00049
00050 template<typename T>
00051 typename boost::enable_if<boost::is_unsigned<T>, T>::type mod(const T& a, const T& b)
00052 {
00053 return a % b;
00054 }
00055 }
00056 }
00057
00058 #endif