// Copyright 2023 Matt Borland // Distributed under the Boost Software License, Version 1.0. // https://www.boost.org/LICENSE_1_0.txt #ifndef BOOST_DECIMAL_DETAIL_APPLY_SIGN_HPP #define BOOST_DECIMAL_DETAIL_APPLY_SIGN_HPP #include #include #ifndef BOOST_DECIMAL_BUILD_MODULE #include #include #endif #ifdef _MSC_VER # pragma warning(push) # pragma warning(disable: 4146) #endif namespace boost { namespace decimal { namespace detail { template , std::enable_if_t, bool> = true> constexpr auto apply_sign(Integer val) noexcept -> Unsigned_Integer { return static_cast(-(static_cast(val))); } template , bool> = true> constexpr auto apply_sign(Unsigned_Integer val) noexcept -> Unsigned_Integer { return val; } template , std::enable_if_t, bool> = true> constexpr auto make_positive_unsigned(Integer val) noexcept -> Unsigned_Integer { return static_cast(val < static_cast(static_cast(0)) ? apply_sign(val) : static_cast(val)); } template , bool> = true> constexpr auto make_positive_unsigned(Unsigned_Integer val) noexcept -> Unsigned_Integer { return val; } template , bool> = true> constexpr auto make_signed_value(Integer val, bool sign) noexcept -> Integer { return sign ? -val : val; } template , std::enable_if_t, bool> = true> constexpr auto make_signed_value(Unsigned_Integer val, bool sign) noexcept -> Integer { const auto signed_val {static_cast(val)}; return sign ? -signed_val : signed_val; } } // namespace detail } // namespace decimal } // namespace boost #ifdef _MSC_VER # pragma warning(pop) #endif #endif // BOOST_DECIMAL_DETAIL_APPLY_SIGN_HPP