2013-08-08 09:54:33 +00:00
|
|
|
/*=============================================================================
|
2016-02-25 09:48:28 +00:00
|
|
|
Copyright (c) 2011-2016 Bolero MURAKAMI
|
2013-08-08 09:54:33 +00:00
|
|
|
https://github.com/bolero-MURAKAMI/Sprout
|
|
|
|
|
|
|
|
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
=============================================================================*/
|
2012-07-06 14:10:49 +00:00
|
|
|
#ifndef SPROUT_MATH_LESS_EQUAL_HPP
|
|
|
|
#define SPROUT_MATH_LESS_EQUAL_HPP
|
|
|
|
|
|
|
|
#include <type_traits>
|
|
|
|
#include <sprout/config.hpp>
|
|
|
|
#include <sprout/math/equal_to.hpp>
|
2012-07-07 05:58:46 +00:00
|
|
|
#include <sprout/type_traits/arithmetic_promote.hpp>
|
2012-07-06 14:10:49 +00:00
|
|
|
#include <sprout/type_traits/enabler_if.hpp>
|
2015-04-04 16:32:49 +00:00
|
|
|
#include <sprout/type_traits/is_signed.hpp>
|
|
|
|
#include <sprout/type_traits/is_unsigned.hpp>
|
2012-07-06 14:10:49 +00:00
|
|
|
|
|
|
|
namespace sprout {
|
|
|
|
namespace math {
|
|
|
|
namespace detail {
|
|
|
|
template<
|
2012-07-07 05:58:46 +00:00
|
|
|
typename FloatType1, typename FloatType2,
|
|
|
|
typename sprout::enabler_if<
|
|
|
|
std::is_floating_point<typename sprout::arithmetic_promote<FloatType1, FloatType2>::type>::value
|
|
|
|
>::type = sprout::enabler
|
2012-07-06 14:10:49 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
2012-07-07 05:58:46 +00:00
|
|
|
less_equal(FloatType1 x, FloatType2 y) {
|
2013-05-07 16:46:40 +00:00
|
|
|
return sprout::math::equal_to(x, y) || x < y;
|
2012-07-06 14:10:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
template<
|
2012-07-07 05:58:46 +00:00
|
|
|
typename IntType1, typename IntType2,
|
|
|
|
typename sprout::enabler_if<
|
|
|
|
std::is_integral<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::value
|
2015-03-31 11:05:32 +00:00
|
|
|
&& (sprout::is_unsigned<IntType1>::value == sprout::is_unsigned<IntType2>::value)
|
2012-07-07 05:58:46 +00:00
|
|
|
>::type = sprout::enabler
|
2012-07-06 14:10:49 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
2012-07-07 05:58:46 +00:00
|
|
|
less_equal(IntType1 x, IntType2 y) {
|
2012-07-06 14:10:49 +00:00
|
|
|
return x <= y;
|
|
|
|
}
|
2012-07-07 05:58:46 +00:00
|
|
|
template<
|
|
|
|
typename IntType1, typename IntType2,
|
|
|
|
typename sprout::enabler_if<
|
|
|
|
std::is_integral<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::value
|
2015-03-31 11:05:32 +00:00
|
|
|
&& sprout::is_signed<IntType1>::value && sprout::is_unsigned<IntType2>::value
|
2012-07-07 05:58:46 +00:00
|
|
|
>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
less_equal(IntType1 x, IntType2 y) {
|
|
|
|
typedef typename std::make_unsigned<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::type type;
|
|
|
|
return x < 0 ? true
|
|
|
|
: static_cast<type>(x) <= static_cast<type>(y)
|
|
|
|
;
|
|
|
|
}
|
|
|
|
template<
|
|
|
|
typename IntType1, typename IntType2,
|
|
|
|
typename sprout::enabler_if<
|
|
|
|
std::is_integral<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::value
|
2015-03-31 11:05:32 +00:00
|
|
|
&& sprout::is_unsigned<IntType1>::value && sprout::is_signed<IntType2>::value
|
2012-07-07 05:58:46 +00:00
|
|
|
>::type = sprout::enabler
|
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
|
|
|
less_equal(IntType1 x, IntType2 y) {
|
|
|
|
typedef typename std::make_unsigned<typename sprout::arithmetic_promote<IntType1, IntType2>::type>::type type;
|
|
|
|
return y < 0 ? false
|
|
|
|
: static_cast<type>(x) <= static_cast<type>(y)
|
|
|
|
;
|
|
|
|
}
|
2012-07-06 14:10:49 +00:00
|
|
|
} // namespace detail
|
|
|
|
//
|
|
|
|
// less_equal
|
|
|
|
//
|
|
|
|
template<
|
2012-07-07 05:58:46 +00:00
|
|
|
typename T, typename U,
|
|
|
|
typename sprout::enabler_if<std::is_arithmetic<T>::value && std::is_arithmetic<U>::value>::type = sprout::enabler
|
2012-07-06 14:10:49 +00:00
|
|
|
>
|
|
|
|
inline SPROUT_CONSTEXPR bool
|
2012-07-07 05:58:46 +00:00
|
|
|
less_equal(T x, U y) {
|
|
|
|
return sprout::math::detail::less_equal(x, y);
|
2012-07-06 14:10:49 +00:00
|
|
|
}
|
|
|
|
} // namespace math
|
|
|
|
} // namespace sprout
|
|
|
|
|
|
|
|
#endif // #ifndef SPROUT_MATH_LESS_EQUAL_HPP
|