Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:45:14

0001 //  (C) Copyright Matt Borland 2021.
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #ifndef BOOST_MATH_CCMATH_COPYSIGN_HPP
0007 #define BOOST_MATH_CCMATH_COPYSIGN_HPP
0008 
0009 #include <cmath>
0010 #include <cstdint>
0011 #include <limits>
0012 #include <type_traits>
0013 #include <boost/math/tools/is_constant_evaluated.hpp>
0014 #include <boost/math/tools/promotion.hpp>
0015 #include <boost/math/tools/config.hpp>
0016 #include <boost/math/ccmath/abs.hpp>
0017 #include <boost/math/ccmath/signbit.hpp>
0018 
0019 namespace boost::math::ccmath {
0020 
0021 namespace detail {
0022 
0023 template <typename T>
0024 constexpr T copysign_impl(const T mag, const T sgn) noexcept
0025 {
0026     if (boost::math::ccmath::signbit(sgn))
0027     {
0028         return -boost::math::ccmath::abs(mag);
0029     }
0030     else
0031     {
0032         return boost::math::ccmath::abs(mag);
0033     }
0034 }
0035 
0036 } // Namespace detail
0037 
0038 template <typename Real, std::enable_if_t<!std::is_integral_v<Real>, bool> = true>
0039 constexpr Real copysign(Real mag, Real sgn) noexcept
0040 {
0041     if(BOOST_MATH_IS_CONSTANT_EVALUATED(mag))
0042     {
0043         return boost::math::ccmath::detail::copysign_impl(mag, sgn);
0044     }
0045     else
0046     {
0047         using std::copysign;
0048         return copysign(mag, sgn);
0049     }
0050 }
0051 
0052 template <typename T1, typename T2>
0053 constexpr auto copysign(T1 mag, T2 sgn) noexcept
0054 {
0055     if (BOOST_MATH_IS_CONSTANT_EVALUATED(mag))
0056     {        
0057         using promoted_type = boost::math::tools::promote_args_2_t<T1, T2>;
0058         return boost::math::ccmath::copysign(static_cast<promoted_type>(mag), static_cast<promoted_type>(sgn));
0059     }
0060     else
0061     {
0062         using std::copysign;
0063         return copysign(mag, sgn);
0064     }
0065 }
0066 
0067 constexpr float copysignf(float mag, float sgn) noexcept
0068 {
0069     return boost::math::ccmath::copysign(mag, sgn);
0070 }
0071 
0072 #ifndef BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS
0073 constexpr long double copysignl(long double mag, long double sgn) noexcept
0074 {
0075     return boost::math::ccmath::copysign(mag, sgn);
0076 }
0077 #endif
0078 
0079 } // Namespaces
0080 
0081 #endif // BOOST_MATH_CCMATH_COPYSIGN_HPP