add sprout/math/comparison.hpp

This commit is contained in:
bolero-MURAKAMI 2012-07-06 23:10:49 +09:00
parent d51bd06eda
commit 1c65d59971
20 changed files with 379 additions and 109 deletions

38
sprout/math/compare.hpp Normal file
View file

@ -0,0 +1,38 @@
#ifndef SPROUT_MATH_COMPARE_HPP
#define SPROUT_MATH_COMPARE_HPP
#include <type_traits>
#include <sprout/config.hpp>
#include <sprout/math/equal_to.hpp>
#include <sprout/math/float_promote.hpp>
#include <sprout/type_traits/enabler_if.hpp>
namespace sprout {
namespace math {
namespace detail {
template<typename T>
inline SPROUT_CONSTEXPR int
compare_impl(T x, T y) {
return sprout::math::equal_to(x, y) ? 0
: x < y ? -1
: 1
;
}
} // namespace detail
//
// compare
//
template<
typename T1,
typename T2,
typename sprout::enabler_if<std::is_arithmetic<T1>::value && std::is_arithmetic<T2>::value>::type = sprout::enabler
>
inline SPROUT_CONSTEXPR int
compare(T1 x, T2 y) {
typedef typename sprout::math::float_promote<T1, T2>::type promoted;
return sprout::math::detail::compare_impl<promoted>(x, y);
}
} // namespace math
} // namespace sprout
#endif // #ifndef SPROUT_MATH_COMPARE_HPP