mirror of
https://github.com/bolero-MURAKAMI/Sprout.git
synced 2024-12-23 21:25:49 +00:00
add math comparison functions
This commit is contained in:
parent
ae77da19e1
commit
3df16007a5
14 changed files with 775 additions and 11 deletions
|
@ -32,7 +32,7 @@
|
|||
#include <sprout/utility/forward.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/bit/operation.hpp>
|
||||
#include <sprout/math/comparison.hpp>
|
||||
#include <sprout/math/comparisons.hpp>
|
||||
#include HDR_FUNCTIONAL_SSCRISK_CEL_OR_SPROUT
|
||||
|
||||
namespace sprout {
|
||||
|
|
|
@ -13,9 +13,15 @@
|
|||
#if !defined(_MSC_VER)
|
||||
# include <cinttypes>
|
||||
#endif
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/detail/nil_base.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -91,4 +97,106 @@ namespace sprout {
|
|||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::imaxdiv_t const& v) {
|
||||
return sprout::hash_values(v.quot, v.rem);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
namespace detail {
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element_impl;
|
||||
template<std::size_t I>
|
||||
struct tuple_element_impl<I, sprout::imaxdiv_t>
|
||||
: public sprout::detail::nil_base
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<0, sprout::imaxdiv_t>
|
||||
: public sprout::identity<std::intmax_t>
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<1, sprout::imaxdiv_t>
|
||||
: public sprout::identity<std::intmax_t>
|
||||
{};
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
struct get_impl;
|
||||
template<>
|
||||
struct get_impl<0, sprout::imaxdiv_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR std::intmax_t& operator()(sprout::imaxdiv_t& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
SPROUT_CONSTEXPR std::intmax_t const& operator()(sprout::imaxdiv_t const& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct get_impl<1, sprout::imaxdiv_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR std::intmax_t& operator()(sprout::imaxdiv_t& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
SPROUT_CONSTEXPR std::intmax_t const& operator()(sprout::imaxdiv_t const& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace tuples
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<>
|
||||
struct tuple_size<sprout::imaxdiv_t>
|
||||
: public sprout::integral_constant<std::size_t, 2>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I>
|
||||
struct tuple_element<I, sprout::imaxdiv_t>
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::imaxdiv_t>
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// tuple_get
|
||||
//
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::imaxdiv_t>::type&
|
||||
tuple_get(sprout::imaxdiv_t& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::imaxdiv_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::imaxdiv_t>::type const&
|
||||
tuple_get(sprout::imaxdiv_t const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::imaxdiv_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::imaxdiv_t>::type&&
|
||||
tuple_get(sprout::imaxdiv_t&& t) SPROUT_NOEXCEPT {
|
||||
return sprout::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CINTTYPES_DIV_HPP
|
||||
|
|
|
@ -55,7 +55,9 @@ namespace sprout {
|
|||
inline SPROUT_CXX14_CONSTEXPR typename std::enable_if<
|
||||
!sprout::detail::has_mem_shrink_to_fit<Container&&>::value
|
||||
>::type
|
||||
container_shrink_to_fit_default(Container&&) {}
|
||||
container_shrink_to_fit_default(Container&&) {
|
||||
return ;
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
namespace container_detail {
|
||||
|
|
|
@ -10,11 +10,25 @@
|
|||
#define SPROUT_CSTDLIB_DIV_HPP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
#include <sprout/utility/move.hpp>
|
||||
#include <sprout/type_traits/integral_constant.hpp>
|
||||
#include <sprout/type_traits/identity.hpp>
|
||||
#include <sprout/detail/nil_base.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// div_t
|
||||
// ldiv_t
|
||||
// lldiv_t
|
||||
//
|
||||
typedef std::div_t div_t;
|
||||
typedef std::ldiv_t ldiv_t;
|
||||
typedef std::lldiv_t lldiv_t;
|
||||
|
||||
namespace detail {
|
||||
template<typename T>
|
||||
|
@ -29,9 +43,9 @@ namespace sprout {
|
|||
SPROUT_STATIC_CONSTEXPR std::size_t offsetof_rem = offsetof(DIV_T, rem); \
|
||||
}
|
||||
|
||||
SPROUT_DETAIL_DIV_T_TRAITS_IMPL(int, std::div_t);
|
||||
SPROUT_DETAIL_DIV_T_TRAITS_IMPL(long, std::ldiv_t);
|
||||
SPROUT_DETAIL_DIV_T_TRAITS_IMPL(long long, std::lldiv_t);
|
||||
SPROUT_DETAIL_DIV_T_TRAITS_IMPL(int, sprout::div_t);
|
||||
SPROUT_DETAIL_DIV_T_TRAITS_IMPL(long, sprout::ldiv_t);
|
||||
SPROUT_DETAIL_DIV_T_TRAITS_IMPL(long long, sprout::lldiv_t);
|
||||
# undef SPROUT_DETAIL_DIV_T_TRAITS_IMPL
|
||||
|
||||
template<typename T>
|
||||
|
@ -64,30 +78,254 @@ namespace sprout {
|
|||
} // namespace detail
|
||||
|
||||
// 7.20.6.2 div<69>Cldiv<69>C‹y‚Ñ lldiv ŠÖ<C5A0>”
|
||||
inline SPROUT_CONSTEXPR std::div_t
|
||||
inline SPROUT_CONSTEXPR sprout::div_t
|
||||
div(int numer, int denom) {
|
||||
return sprout::detail::div_impl(numer, denom);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR std::ldiv_t
|
||||
inline SPROUT_CONSTEXPR sprout::ldiv_t
|
||||
ldiv(long numer, long denom) {
|
||||
return sprout::detail::div_impl(numer, denom);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR std::lldiv_t
|
||||
inline SPROUT_CONSTEXPR sprout::lldiv_t
|
||||
lldiv(long long numer, long long denom) {
|
||||
return sprout::detail::div_impl(numer, denom);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR std::ldiv_t
|
||||
inline SPROUT_CONSTEXPR sprout::ldiv_t
|
||||
div(long numer, long denom) {
|
||||
return sprout::ldiv(numer, denom);
|
||||
}
|
||||
|
||||
inline SPROUT_CONSTEXPR std::lldiv_t
|
||||
inline SPROUT_CONSTEXPR sprout::lldiv_t
|
||||
div(long long numer, long long denom) {
|
||||
return sprout::lldiv(numer, denom);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::div_t const& v) {
|
||||
return sprout::hash_values(v.quot, v.rem);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::ldiv_t const& v) {
|
||||
return sprout::hash_values(v.quot, v.rem);
|
||||
}
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::lldiv_t const& v) {
|
||||
return sprout::hash_values(v.quot, v.rem);
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
namespace tuples {
|
||||
namespace detail {
|
||||
template<std::size_t I, typename T>
|
||||
struct tuple_element_impl;
|
||||
template<std::size_t I>
|
||||
struct tuple_element_impl<I, sprout::div_t>
|
||||
: public sprout::detail::nil_base
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<0, sprout::div_t>
|
||||
: public sprout::identity<int>
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<1, sprout::div_t>
|
||||
: public sprout::identity<int>
|
||||
{};
|
||||
template<std::size_t I>
|
||||
struct tuple_element_impl<I, sprout::ldiv_t>
|
||||
: public sprout::detail::nil_base
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<0, sprout::ldiv_t>
|
||||
: public sprout::identity<long>
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<1, sprout::ldiv_t>
|
||||
: public sprout::identity<long>
|
||||
{};
|
||||
template<std::size_t I>
|
||||
struct tuple_element_impl<I, sprout::lldiv_t>
|
||||
: public sprout::detail::nil_base
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<0, sprout::lldiv_t>
|
||||
: public sprout::identity<long long>
|
||||
{};
|
||||
template<>
|
||||
struct tuple_element_impl<1, sprout::lldiv_t>
|
||||
: public sprout::identity<long long>
|
||||
{};
|
||||
|
||||
template<std::size_t I, typename T>
|
||||
struct get_impl;
|
||||
template<>
|
||||
struct get_impl<0, sprout::div_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR int& operator()(sprout::div_t& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
SPROUT_CONSTEXPR int const& operator()(sprout::div_t const& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct get_impl<1, sprout::div_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR int& operator()(sprout::div_t& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
SPROUT_CONSTEXPR int const& operator()(sprout::div_t const& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct get_impl<0, sprout::ldiv_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR long& operator()(sprout::ldiv_t& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
SPROUT_CONSTEXPR long const& operator()(sprout::ldiv_t const& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct get_impl<1, sprout::ldiv_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR long& operator()(sprout::ldiv_t& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
SPROUT_CONSTEXPR long const& operator()(sprout::ldiv_t const& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct get_impl<0, sprout::lldiv_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR long long& operator()(sprout::lldiv_t& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
SPROUT_CONSTEXPR long long const& operator()(sprout::lldiv_t const& t) const {
|
||||
return t.quot;
|
||||
}
|
||||
};
|
||||
template<>
|
||||
struct get_impl<1, sprout::lldiv_t> {
|
||||
public:
|
||||
SPROUT_CONSTEXPR long long& operator()(sprout::lldiv_t& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
SPROUT_CONSTEXPR long long const& operator()(sprout::lldiv_t const& t) const {
|
||||
return t.rem;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
} // namespace tuples
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// tuple_size
|
||||
//
|
||||
template<>
|
||||
struct tuple_size<sprout::div_t>
|
||||
: public sprout::integral_constant<std::size_t, 2>
|
||||
{};
|
||||
template<>
|
||||
struct tuple_size<sprout::ldiv_t>
|
||||
: public sprout::integral_constant<std::size_t, 2>
|
||||
{};
|
||||
template<>
|
||||
struct tuple_size<sprout::lldiv_t>
|
||||
: public sprout::integral_constant<std::size_t, 2>
|
||||
{};
|
||||
|
||||
//
|
||||
// tuple_element
|
||||
//
|
||||
template<std::size_t I>
|
||||
struct tuple_element<I, sprout::div_t>
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::div_t>
|
||||
{};
|
||||
template<std::size_t I>
|
||||
struct tuple_element<I, sprout::ldiv_t>
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::ldiv_t>
|
||||
{};
|
||||
template<std::size_t I>
|
||||
struct tuple_element<I, sprout::lldiv_t>
|
||||
: public sprout::tuples::detail::tuple_element_impl<I, sprout::lldiv_t>
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// tuple_get
|
||||
//
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::div_t>::type&
|
||||
tuple_get(sprout::div_t& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::div_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::div_t>::type const&
|
||||
tuple_get(sprout::div_t const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::div_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::div_t>::type&&
|
||||
tuple_get(sprout::div_t&& t) SPROUT_NOEXCEPT {
|
||||
return sprout::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::ldiv_t>::type&
|
||||
tuple_get(sprout::ldiv_t& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::ldiv_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::ldiv_t>::type const&
|
||||
tuple_get(sprout::ldiv_t const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::ldiv_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::ldiv_t>::type&&
|
||||
tuple_get(sprout::ldiv_t&& t) SPROUT_NOEXCEPT {
|
||||
return sprout::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::lldiv_t>::type&
|
||||
tuple_get(sprout::lldiv_t& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::lldiv_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::lldiv_t>::type const&
|
||||
tuple_get(sprout::lldiv_t const& t) SPROUT_NOEXCEPT {
|
||||
static_assert(I < 2, "tuple_get: index out of range");
|
||||
return sprout::tuples::detail::get_impl<I, sprout::lldiv_t>()(t);
|
||||
}
|
||||
template<std::size_t I>
|
||||
inline SPROUT_CONSTEXPR typename sprout::tuples::tuple_element<I, sprout::lldiv_t>::type&&
|
||||
tuple_get(sprout::lldiv_t&& t) SPROUT_NOEXCEPT {
|
||||
return sprout::move(sprout::tuples::get<I>(t));
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_CSTDLIB_DIV_HPP
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#include <utility>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/workaround/std/cstddef.hpp>
|
||||
#include <sprout/functional/hash.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
|
@ -246,4 +247,32 @@ namespace sprout {
|
|||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// hash_value
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR std::size_t
|
||||
hash_value(sprout::exempt_ptr<T> const& v) {
|
||||
return sprout::hash_value(v.get());
|
||||
}
|
||||
} // namespace sprout
|
||||
|
||||
namespace std {
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic push
|
||||
# pragma clang diagnostic ignored "-Wmismatched-tags"
|
||||
#endif
|
||||
//
|
||||
// hash
|
||||
//
|
||||
template<typename T>
|
||||
struct hash<sprout::exempt_ptr<T> >
|
||||
: public sprout::hash<sprout::exempt_ptr<T> >
|
||||
{};
|
||||
#if defined(__clang__)
|
||||
# pragma clang diagnostic pop
|
||||
#endif
|
||||
} // namespace std
|
||||
|
||||
#endif // #ifndef SPROUT_EXEMPT_PTR_HPP
|
||||
|
|
|
@ -9,6 +9,12 @@
|
|||
#define SPROUT_MATH_COMPARISON_HPP
|
||||
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/isgreater.hpp>
|
||||
#include <sprout/math/isgreaterequal.hpp>
|
||||
#include <sprout/math/isless.hpp>
|
||||
#include <sprout/math/islessequal.hpp>
|
||||
#include <sprout/math/islessgreater.hpp>
|
||||
#include <sprout/math/isunordered.hpp>
|
||||
#include <sprout/math/equal_to.hpp>
|
||||
#include <sprout/math/not_equal_to.hpp>
|
||||
#include <sprout/math/greater.hpp>
|
|
@ -13,7 +13,7 @@
|
|||
#include <sprout/math/common_factor.hpp>
|
||||
#include <sprout/math/factorial.hpp>
|
||||
#include <sprout/math/bernoulli.hpp>
|
||||
#include <sprout/math/comparison.hpp>
|
||||
#include <sprout/math/comparisons.hpp>
|
||||
#include <sprout/math/integer.hpp>
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_FUNCTIONS_HPP
|
||||
|
|
63
sprout/math/isgreater.hpp
Normal file
63
sprout/math/isgreater.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_MATH_ISGREATER_HPP
|
||||
#define SPROUT_MATH_ISGREATER_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
builtin_isgreater(FloatType x, FloatType y) {
|
||||
return __builtin_isgreater(x, y);
|
||||
}
|
||||
#endif
|
||||
} // namespace detail
|
||||
//
|
||||
// isgreater
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isgreater(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_isgreater(x, y)
|
||||
#else
|
||||
!sprout::math::isnan(x) && !sprout::math::isnan(y) && (x > y)
|
||||
#endif
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isgreater(ArithmeticType1 x, ArithmeticType2 y) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
return sprout::math::isgreater(static_cast<type>(x), static_cast<type>(y));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::isgreater;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ISGREATER_HPP
|
63
sprout/math/isgreaterequal.hpp
Normal file
63
sprout/math/isgreaterequal.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_MATH_ISGREATEREQUAL_HPP
|
||||
#define SPROUT_MATH_ISGREATEREQUAL_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
builtin_isgreaterequal(FloatType x, FloatType y) {
|
||||
return __builtin_isgreaterequal(x, y);
|
||||
}
|
||||
#endif
|
||||
} // namespace detail
|
||||
//
|
||||
// isgreaterequal
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isgreaterequal(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_isgreaterequal(x, y)
|
||||
#else
|
||||
!sprout::math::isnan(x) && !sprout::math::isnan(y) && (x >= y)
|
||||
#endif
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isgreaterequal(ArithmeticType1 x, ArithmeticType2 y) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
return sprout::math::isgreaterequal(static_cast<type>(x), static_cast<type>(y));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::isgreaterequal;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ISGREATEREQUAL_HPP
|
63
sprout/math/isless.hpp
Normal file
63
sprout/math/isless.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_MATH_ISLESS_HPP
|
||||
#define SPROUT_MATH_ISLESS_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
builtin_isless(FloatType x, FloatType y) {
|
||||
return __builtin_isless(x, y);
|
||||
}
|
||||
#endif
|
||||
} // namespace detail
|
||||
//
|
||||
// isless
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isless(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_isless(x, y)
|
||||
#else
|
||||
!sprout::math::isnan(x) && !sprout::math::isnan(y) && (x < y)
|
||||
#endif
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isless(ArithmeticType1 x, ArithmeticType2 y) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
return sprout::math::isless(static_cast<type>(x), static_cast<type>(y));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::isless;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ISLESS_HPP
|
63
sprout/math/islessequal.hpp
Normal file
63
sprout/math/islessequal.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_MATH_ISLESSEQUAL_HPP
|
||||
#define SPROUT_MATH_ISLESSEQUAL_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
builtin_islessequal(FloatType x, FloatType y) {
|
||||
return __builtin_islessequal(x, y);
|
||||
}
|
||||
#endif
|
||||
} // namespace detail
|
||||
//
|
||||
// islessequal
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
islessequal(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_islessequal(x, y)
|
||||
#else
|
||||
!sprout::math::isnan(x) && !sprout::math::isnan(y) && (x < y)
|
||||
#endif
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
islessequal(ArithmeticType1 x, ArithmeticType2 y) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
return sprout::math::islessequal(static_cast<type>(x), static_cast<type>(y));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::islessequal;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ISLESSEQUAL_HPP
|
63
sprout/math/islessgreater.hpp
Normal file
63
sprout/math/islessgreater.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_MATH_ISLESSGREATER_HPP
|
||||
#define SPROUT_MATH_ISLESSGREATER_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
builtin_islessgreater(FloatType x, FloatType y) {
|
||||
return __builtin_islessgreater(x, y);
|
||||
}
|
||||
#endif
|
||||
} // namespace detail
|
||||
//
|
||||
// islessgreater
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
islessgreater(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_islessgreater(x, y)
|
||||
#else
|
||||
!sprout::math::isnan(x) && !sprout::math::isnan(y) && ((x < y) || (x > y))
|
||||
#endif
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
islessgreater(ArithmeticType1 x, ArithmeticType2 y) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
return sprout::math::islessgreater(static_cast<type>(x), static_cast<type>(y));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::islessgreater;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ISLESSGREATER_HPP
|
63
sprout/math/isunordered.hpp
Normal file
63
sprout/math/isunordered.hpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*=============================================================================
|
||||
Copyright (c) 2011-2014 Bolero MURAKAMI
|
||||
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)
|
||||
=============================================================================*/
|
||||
#ifndef SPROUT_MATH_ISUNORDERED_HPP
|
||||
#define SPROUT_MATH_ISUNORDERED_HPP
|
||||
|
||||
#include <type_traits>
|
||||
#include <sprout/config.hpp>
|
||||
#include <sprout/math/detail/config.hpp>
|
||||
#include <sprout/math/isnan.hpp>
|
||||
#include <sprout/type_traits/float_promote.hpp>
|
||||
#include <sprout/type_traits/enabler_if.hpp>
|
||||
|
||||
namespace sprout {
|
||||
namespace math {
|
||||
namespace detail {
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
template<typename FloatType>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
builtin_isunordered(FloatType x, FloatType y) {
|
||||
return __builtin_isunordered(x, y);
|
||||
}
|
||||
#endif
|
||||
} // namespace detail
|
||||
//
|
||||
// isunordered
|
||||
//
|
||||
template<
|
||||
typename FloatType,
|
||||
typename sprout::enabler_if<std::is_floating_point<FloatType>::value>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isunordered(FloatType x, FloatType y) {
|
||||
return
|
||||
#if SPROUT_USE_BUILTIN_CMATH_FUNCTION
|
||||
sprout::math::detail::builtin_isunordered(x, y)
|
||||
#else
|
||||
sprout::math::isnan(x) || sprout::math::isnan(y)
|
||||
#endif
|
||||
;
|
||||
}
|
||||
template<
|
||||
typename ArithmeticType1,
|
||||
typename ArithmeticType2,
|
||||
typename sprout::enabler_if<
|
||||
std::is_arithmetic<ArithmeticType1>::value && std::is_arithmetic<ArithmeticType2>::value
|
||||
>::type = sprout::enabler
|
||||
>
|
||||
inline SPROUT_CONSTEXPR bool
|
||||
isunordered(ArithmeticType1 x, ArithmeticType2 y) {
|
||||
typedef typename sprout::float_promote<ArithmeticType1, ArithmeticType2>::type type;
|
||||
return sprout::math::isunordered(static_cast<type>(x), static_cast<type>(y));
|
||||
}
|
||||
} // namespace math
|
||||
|
||||
using sprout::math::isunordered;
|
||||
} // namespace sprout
|
||||
|
||||
#endif // #ifndef SPROUT_MATH_ISUNORDERED_HPP
|
|
@ -12,6 +12,9 @@
|
|||
#include <sprout/config.hpp>
|
||||
|
||||
namespace sprout {
|
||||
//
|
||||
// unmove
|
||||
//
|
||||
template<typename T>
|
||||
inline SPROUT_CONSTEXPR typename std::remove_reference<T>::type&
|
||||
unmove(T&& x) SPROUT_NOEXCEPT {
|
||||
|
|
Loading…
Reference in a new issue