/*============================================================================= Copyright (c) 2011-2015 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_EQUAL_TO_HPP #define SPROUT_MATH_EQUAL_TO_HPP #include #include #include #include #include #include #include namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR T max3(T x, T y, T z) { return sprout::max(sprout::max(x, y), z); } template inline SPROUT_CONSTEXPR bool equal_to_impl(FloatType x, FloatType y) { return x == y || sprout::fabs(x - y) <= sprout::numeric_limits::epsilon() * sprout::math::detail::max3(sprout::fabs(x), sprout::fabs(y), FloatType(1)) ; } template< typename FloatType1, typename FloatType2, typename sprout::enabler_if< std::is_floating_point::type>::value >::type = sprout::enabler > inline SPROUT_CONSTEXPR bool equal_to(FloatType1 x, FloatType2 y) { typedef typename sprout::arithmetic_promote::type type; return sprout::math::detail::equal_to_impl(x, y); } template< typename IntType1, typename IntType2, typename sprout::enabler_if< std::is_integral::type>::value >::type = sprout::enabler > inline SPROUT_CONSTEXPR bool equal_to(IntType1 x, IntType2 y) { return x == y; } } // namespace detail // // equal_to // template< typename T, typename U, typename sprout::enabler_if::value && std::is_arithmetic::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR bool equal_to(T x, U y) { return sprout::math::detail::equal_to(x, y); } } // namespace math } // namespace sprout #endif // #ifndef SPROUT_MATH_EQUAL_TO_HPP