123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311 |
- #ifndef BOOST_MATH_PROMOTION_HPP
- #define BOOST_MATH_PROMOTION_HPP
- #ifdef _MSC_VER
- #pragma once
- #endif
- #include <boost/math/tools/config.hpp>
- #include <type_traits>
- #if defined __has_include
- # if __cplusplus > 202002L || (defined(_MSVC_LANG) && _MSVC_LANG > 202002L)
- # if __has_include (<stdfloat>)
- # include <stdfloat>
- # endif
- # endif
- #endif
- namespace boost
- {
- namespace math
- {
- namespace tools
- {
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- template <class T>
- struct promote_arg
- {
- using type = typename std::conditional<std::is_integral<T>::value, double, T>::type;
- };
-
-
- template <> struct promote_arg<float> { using type = float; };
- template <> struct promote_arg<double>{ using type = double; };
- template <> struct promote_arg<long double> { using type = long double; };
- template <> struct promote_arg<int> { using type = double; };
- #ifdef __STDCPP_FLOAT16_T__
- template <> struct promote_arg<std::float16_t> { using type = std::float16_t; };
- #endif
- #ifdef __STDCPP_FLOAT32_T__
- template <> struct promote_arg<std::float32_t> { using type = std::float32_t; };
- #endif
- #ifdef __STDCPP_FLOAT64_T__
- template <> struct promote_arg<std::float64_t> { using type = std::float64_t; };
- #endif
- #ifdef __STDCPP_FLOAT128_T__
- template <> struct promote_arg<std::float128_t> { using type = std::float128_t; };
- #endif
- template <typename T>
- using promote_arg_t = typename promote_arg<T>::type;
- template <class T1, class T2>
- struct promote_args_2
- {
-
- using T1P = typename promote_arg<T1>::type;
- using T2P = typename promote_arg<T2>::type;
- using intermediate_type = typename std::conditional<
- std::is_floating_point<T1P>::value && std::is_floating_point<T2P>::value,
- #ifdef __STDCPP_FLOAT128_T__
- typename std::conditional<std::is_same<std::float128_t, T1P>::value || std::is_same<std::float128_t, T2P>::value,
- std::float128_t,
- #endif
- #ifdef BOOST_MATH_USE_FLOAT128
- typename std::conditional<std::is_same<__float128, T1P>::value || std::is_same<__float128, T2P>::value,
- __float128,
- #endif
- typename std::conditional<std::is_same<long double, T1P>::value || std::is_same<long double, T2P>::value,
- long double,
- #ifdef __STDCPP_FLOAT64_T__
- typename std::conditional<std::is_same<std::float64_t, T1P>::value || std::is_same<std::float64_t, T2P>::value,
- std::float64_t,
- #endif
- typename std::conditional<std::is_same<double, T1P>::value || std::is_same<double, T2P>::value,
- double,
- #ifdef __STDCPP_FLOAT32_T__
- typename std::conditional<std::is_same<std::float32_t, T1P>::value || std::is_same<std::float32_t, T2P>::value,
- std::float32_t,
- #endif
- float
- >::type
- #ifdef BOOST_MATH_USE_FLOAT128
- >::type
- #endif
- #ifdef __STDCPP_FLOAT128_T__
- >::type
- #endif
- #ifdef __STDCPP_FLOAT64_T__
- >::type
- #endif
- #ifdef __STDCPP_FLOAT32_T__
- >::type
- #endif
- >::type,
-
- typename std::conditional<!std::is_floating_point<T2P>::value && std::is_convertible<T1P, T2P>::value, T2P, T1P>::type>::type;
- #ifdef __STDCPP_FLOAT64_T__
-
- using type = std::conditional_t<(sizeof(double) == sizeof(long double) && std::is_same<intermediate_type, long double>::value), std::float64_t, intermediate_type>;
- #else
- using type = intermediate_type;
- #endif
- };
-
-
- template <> struct promote_args_2<float, float> { using type = float; };
- template <> struct promote_args_2<double, double>{ using type = double; };
- template <> struct promote_args_2<long double, long double> { using type = long double; };
- template <> struct promote_args_2<int, int> { using type = double; };
- template <> struct promote_args_2<int, float> { using type = double; };
- template <> struct promote_args_2<float, int> { using type = double; };
- template <> struct promote_args_2<int, double> { using type = double; };
- template <> struct promote_args_2<double, int> { using type = double; };
- template <> struct promote_args_2<int, long double> { using type = long double; };
- template <> struct promote_args_2<long double, int> { using type = long double; };
- template <> struct promote_args_2<float, double> { using type = double; };
- template <> struct promote_args_2<double, float> { using type = double; };
- template <> struct promote_args_2<float, long double> { using type = long double; };
- template <> struct promote_args_2<long double, float> { using type = long double; };
- template <> struct promote_args_2<double, long double> { using type = long double; };
- template <> struct promote_args_2<long double, double> { using type = long double; };
- #ifdef __STDCPP_FLOAT128_T__
- template <> struct promote_args_2<int, std::float128_t> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float128_t, int> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float128_t, float> { using type = std::float128_t; };
- template <> struct promote_args_2<float, std::float128_t> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float128_t, double> { using type = std::float128_t; };
- template <> struct promote_args_2<double, std::float128_t> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float128_t, long double> { using type = std::float128_t; };
- template <> struct promote_args_2<long double, std::float128_t> { using type = std::float128_t; };
- #ifdef __STDCPP_FLOAT16_T__
- template <> struct promote_args_2<std::float128_t, std::float16_t> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float16_t, std::float128_t> { using type = std::float128_t; };
- #endif
- #ifdef __STDCPP_FLOAT32_T__
- template <> struct promote_args_2<std::float128_t, std::float32_t> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float32_t, std::float128_t> { using type = std::float128_t; };
- #endif
- #ifdef __STDCPP_FLOAT64_T__
- template <> struct promote_args_2<std::float128_t, std::float64_t> { using type = std::float128_t; };
- template <> struct promote_args_2<std::float64_t, std::float128_t> { using type = std::float128_t; };
- #endif
- template <> struct promote_args_2<std::float128_t, std::float128_t> { using type = std::float128_t; };
- #endif
- #ifdef __STDCPP_FLOAT64_T__
- template <> struct promote_args_2<int, std::float64_t> { using type = std::float64_t; };
- template <> struct promote_args_2<std::float64_t, int> { using type = std::float64_t; };
- template <> struct promote_args_2<std::float64_t, float> { using type = std::float64_t; };
- template <> struct promote_args_2<float, std::float64_t> { using type = std::float64_t; };
- template <> struct promote_args_2<std::float64_t, double> { using type = std::float64_t; };
- template <> struct promote_args_2<double, std::float64_t> { using type = std::float64_t; };
- template <> struct promote_args_2<std::float64_t, long double> { using type = long double; };
- template <> struct promote_args_2<long double, std::float64_t> { using type = long double; };
- #ifdef __STDCPP_FLOAT16_T__
- template <> struct promote_args_2<std::float64_t, std::float16_t> { using type = std::float64_t; };
- template <> struct promote_args_2<std::float16_t, std::float64_t> { using type = std::float64_t; };
- #endif
- #ifdef __STDCPP_FLOAT32_T__
- template <> struct promote_args_2<std::float64_t, std::float32_t> { using type = std::float64_t; };
- template <> struct promote_args_2<std::float32_t, std::float64_t> { using type = std::float64_t; };
- #endif
- template <> struct promote_args_2<std::float64_t, std::float64_t> { using type = std::float64_t; };
- #endif
- #ifdef __STDCPP_FLOAT32_T__
- template <> struct promote_args_2<int, std::float32_t> { using type = std::float32_t; };
- template <> struct promote_args_2<std::float32_t, int> { using type = std::float32_t; };
- template <> struct promote_args_2<std::float32_t, float> { using type = std::float32_t; };
- template <> struct promote_args_2<float, std::float32_t> { using type = std::float32_t; };
- template <> struct promote_args_2<std::float32_t, double> { using type = double; };
- template <> struct promote_args_2<double, std::float32_t> { using type = double; };
- template <> struct promote_args_2<std::float32_t, long double> { using type = long double; };
- template <> struct promote_args_2<long double, std::float32_t> { using type = long double; };
- #ifdef __STDCPP_FLOAT16_T__
- template <> struct promote_args_2<std::float32_t, std::float16_t> { using type = std::float32_t; };
- template <> struct promote_args_2<std::float16_t, std::float32_t> { using type = std::float32_t; };
- #endif
- template <> struct promote_args_2<std::float32_t, std::float32_t> { using type = std::float32_t; };
- #endif
- #ifdef __STDCPP_FLOAT16_T__
- template <> struct promote_args_2<int, std::float16_t> { using type = std::float16_t; };
- template <> struct promote_args_2<std::float16_t, int> { using type = std::float16_t; };
- template <> struct promote_args_2<std::float16_t, float> { using type = float; };
- template <> struct promote_args_2<float, std::float16_t> { using type = float; };
- template <> struct promote_args_2<std::float16_t, double> { using type = double; };
- template <> struct promote_args_2<double, std::float16_t> { using type = double; };
- template <> struct promote_args_2<std::float16_t, long double> { using type = long double; };
- template <> struct promote_args_2<long double, std::float16_t> { using type = long double; };
- template <> struct promote_args_2<std::float16_t, std::float16_t> { using type = std::float16_t; };
- #endif
- template <typename T, typename U>
- using promote_args_2_t = typename promote_args_2<T, U>::type;
- template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float>
- struct promote_args
- {
- using type = typename promote_args_2<
- typename std::remove_cv<T1>::type,
- typename promote_args_2<
- typename std::remove_cv<T2>::type,
- typename promote_args_2<
- typename std::remove_cv<T3>::type,
- typename promote_args_2<
- typename std::remove_cv<T4>::type,
- typename promote_args_2<
- typename std::remove_cv<T5>::type, typename std::remove_cv<T6>::type
- >::type
- >::type
- >::type
- >::type
- >::type;
- #if defined(BOOST_MATH_NO_LONG_DOUBLE_MATH_FUNCTIONS)
-
-
-
- static_assert((0 == std::is_same<type, long double>::value), "Sorry, but this platform does not have sufficient long double support for the special functions to be reliably implemented.");
- #endif
- };
- template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float>
- using promote_args_t = typename promote_args<T1, T2, T3, T4, T5, T6>::type;
-
-
-
-
-
- template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float>
- struct promote_args_permissive
- {
- using type = typename promote_args_2<
- typename std::remove_cv<T1>::type,
- typename promote_args_2<
- typename std::remove_cv<T2>::type,
- typename promote_args_2<
- typename std::remove_cv<T3>::type,
- typename promote_args_2<
- typename std::remove_cv<T4>::type,
- typename promote_args_2<
- typename std::remove_cv<T5>::type, typename std::remove_cv<T6>::type
- >::type
- >::type
- >::type
- >::type
- >::type;
- };
- template <class T1, class T2=float, class T3=float, class T4=float, class T5=float, class T6=float>
- using promote_args_permissive_t = typename promote_args_permissive<T1, T2, T3, T4, T5, T6>::type;
- }
- }
- }
- #endif
|