#ifndef SPROUT_MATH_ATAN2_HPP #define SPROUT_MATH_ATAN2_HPP #include #include #include #include #include #include #include #include #include #include #include namespace sprout { namespace math { namespace detail { template inline SPROUT_CONSTEXPR T atan2_impl(T y, T x) { return x < 0 ? sprout::math::atan(y / x) + ( y < 0 ? -sprout::math::pi() : sprout::math::pi() ) : sprout::math::atan(y / x) ; } template< typename FloatType, typename sprout::enabler_if::value>::type = sprout::enabler > inline SPROUT_CONSTEXPR FloatType atan2(FloatType y, FloatType x) { return x == -std::numeric_limits::infinity() ? y == std::numeric_limits::infinity() ? sprout::math::three_quarters_pi() : y == -std::numeric_limits::infinity() ? -sprout::math::three_quarters_pi() : sprout::math::copysign(sprout::math::pi(), y) : x == std::numeric_limits::infinity() ? y == std::numeric_limits::infinity() ? sprout::math::quarter_pi() : y == -std::numeric_limits::infinity() ? -sprout::math::quarter_pi() : sprout::math::copysign(FloatType(0), y) : y == std::numeric_limits::infinity() ? sprout::math::half_pi() : y == -std::numeric_limits::infinity() ? -sprout::math::half_pi() #if SPROUT_USE_BUILTIN_CMATH_FUNCTION : std::atan2(y, x) #else : y == 0 ? x < 0 ? sprout::math::copysign(sprout::math::pi(), y) : x > 0 ? sprout::math::copysign(FloatType(0), y) : sprout::math::signbit(x) ? sprout::math::copysign(sprout::math::pi(), y) : sprout::math::copysign(FloatType(0), y) : x == 0 ? y < 0 ? -sprout::math::half_pi() : sprout::math::half_pi() : static_cast( sprout::math::detail::atan2_impl( static_cast::type>(y), static_cast::type>(x) ) ) #endif ; } template< typename ArithmeticType1, typename ArithmeticType2, typename sprout::enabler_if< std::is_arithmetic::value && std::is_arithmetic::value >::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::float_promote::type atan2(ArithmeticType1 y, ArithmeticType2 x) { typedef typename sprout::float_promote::type type; return sprout::math::detail::atan2(static_cast(y), static_cast(x)); } } // namespace detail // // atan2 // template< typename ArithmeticType1, typename ArithmeticType2, typename sprout::enabler_if< std::is_arithmetic::value && std::is_arithmetic::value >::type = sprout::enabler > inline SPROUT_CONSTEXPR typename sprout::float_promote::type atan2(ArithmeticType1 y, ArithmeticType2 x) { return sprout::math::detail::atan2(y, x); } } // namespace math using sprout::math::atan2; } // namespace sprout #endif // #ifndef SPROUT_MATH_ATAN2_HPP