/*============================================================================= Copyright (c) 2011-2019 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_QUATERNION_ABS_HPP #define SPROUT_MATH_QUATERNION_ABS_HPP #include #include #include #include #include #include #include namespace sprout { namespace math { // // abs // namespace detail { template inline SPROUT_CONSTEXPR T abs_q_impl_3(sprout::array const& temp, T const& maxim) { return maxim * sprout::math::sqrt(sprout::math::detail::sum(sprout::math::detail::mul(temp, temp))); } template inline SPROUT_CONSTEXPR T abs_q_impl_2(sprout::array const& temp, T const& maxim) { return sprout::math::detail::abs_q_impl_3( sprout::math::detail::mul(temp, maxim), maxim ); } template inline SPROUT_CONSTEXPR T abs_q_impl_1(sprout::array const& temp, T const& maxim) { return maxim == static_cast(0) ? sprout::math::quaternion(maxim) : sprout::math::detail::abs_q_impl_2( temp, static_cast(1) / maxim ) ; } template inline SPROUT_CONSTEXPR T abs_q_impl(sprout::array const& temp) { return sprout::math::detail::abs_q_impl_1( temp, sprout::math::detail::abs_max(temp) ); } } // namespace detail template inline SPROUT_CONSTEXPR T abs(sprout::math::quaternion const& q) { return sprout::math::detail::abs_q_impl( sprout::array{{ q.R_component_1(), q.R_component_2(), q.R_component_3(), q.R_component_4() }} ); } } // namespace math using sprout::math::abs; } // namespace sprout #endif // #ifndef SPROUT_MATH_QUATERNION_ABS_HPP