mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2025-07-14 15:04:09 +00:00
fix math/comparison.hpp
This commit is contained in:
parent
1c65d59971
commit
3b6ba46f17
23 changed files with 389 additions and 175 deletions
|
@ -4,33 +4,24 @@
|
|||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/equal_to.hpp>
|
||||
#include <sprout/math/float_promote.hpp>
|
||||
#include <sprout/math/less.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
|
||||
typename T, typename U,
|
||||
typename sprout::enabler_if<std::is_arithmetic<T>::value && std::is_arithmetic<U>::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);
|
||||
compare(T x, U y) {
|
||||
return sprout::math::equal_to(x, y) ? 0
|
||||
: sprout::math::less(x, y) ? -1
|
||||
: 1
|
||||
;
|
||||
}
|
||||
} // namespace math
|
||||
} // namespace sprout
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue