mirror of
https://github.com/boostorg/math.git
synced 2026-01-19 04:22:09 +00:00
Make trunc GPU compatible
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
// Copyright John Maddock 2008.
|
||||
// Copyright Matt Borland 2024
|
||||
|
||||
// Use, modification and distribution are subject to the
|
||||
// Boost Software License, Version 1.0.
|
||||
@@ -21,21 +22,21 @@ namespace boost
|
||||
{
|
||||
|
||||
template <class T, class Policy>
|
||||
typename tools::promote_args<T>::type trunc(const T& v, const Policy& pol);
|
||||
BOOST_MATH_GPU_ENABLED typename tools::promote_args<T>::type trunc(const T& v, const Policy& pol);
|
||||
template <class T>
|
||||
typename tools::promote_args<T>::type trunc(const T& v);
|
||||
BOOST_MATH_GPU_ENABLED typename tools::promote_args<T>::type trunc(const T& v);
|
||||
template <class T, class Policy>
|
||||
int itrunc(const T& v, const Policy& pol);
|
||||
BOOST_MATH_GPU_ENABLED int itrunc(const T& v, const Policy& pol);
|
||||
template <class T>
|
||||
int itrunc(const T& v);
|
||||
BOOST_MATH_GPU_ENABLED int itrunc(const T& v);
|
||||
template <class T, class Policy>
|
||||
long ltrunc(const T& v, const Policy& pol);
|
||||
BOOST_MATH_GPU_ENABLED long ltrunc(const T& v, const Policy& pol);
|
||||
template <class T>
|
||||
long ltrunc(const T& v);
|
||||
BOOST_MATH_GPU_ENABLED long ltrunc(const T& v);
|
||||
template <class T, class Policy>
|
||||
long long lltrunc(const T& v, const Policy& pol);
|
||||
BOOST_MATH_GPU_ENABLED long long lltrunc(const T& v, const Policy& pol);
|
||||
template <class T>
|
||||
long long lltrunc(const T& v);
|
||||
BOOST_MATH_GPU_ENABLED long long lltrunc(const T& v);
|
||||
template <class T, class Policy>
|
||||
typename tools::promote_args<T>::type round(const T& v, const Policy& pol);
|
||||
template <class T>
|
||||
|
||||
@@ -1198,7 +1198,7 @@ namespace boost
|
||||
inline T modf(const T& v, long long* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\
|
||||
\
|
||||
template <class T>\
|
||||
inline long long lltrunc(const T& v){ using boost::math::lltrunc; return lltrunc(v, Policy()); }\
|
||||
BOOST_MATH_GPU_ENABLED inline long long lltrunc(const T& v){ using boost::math::lltrunc; return lltrunc(v, Policy()); }\
|
||||
\
|
||||
template <class T>\
|
||||
inline long long llround(const T& v){ using boost::math::llround; return llround(v, Policy()); }\
|
||||
@@ -1607,13 +1607,13 @@ template <class OutputIterator, class T>\
|
||||
inline long lround(const T& v){ using boost::math::lround; return lround(v, Policy()); }\
|
||||
\
|
||||
template <class T>\
|
||||
inline T trunc(const T& v){ using boost::math::trunc; return trunc(v, Policy()); }\
|
||||
BOOST_MATH_GPU_ENABLED inline T trunc(const T& v){ using boost::math::trunc; return trunc(v, Policy()); }\
|
||||
\
|
||||
template <class T>\
|
||||
inline int itrunc(const T& v){ using boost::math::itrunc; return itrunc(v, Policy()); }\
|
||||
BOOST_MATH_GPU_ENABLED inline int itrunc(const T& v){ using boost::math::itrunc; return itrunc(v, Policy()); }\
|
||||
\
|
||||
template <class T>\
|
||||
inline long ltrunc(const T& v){ using boost::math::ltrunc; return ltrunc(v, Policy()); }\
|
||||
BOOST_MATH_GPU_ENABLED inline long ltrunc(const T& v){ using boost::math::ltrunc; return ltrunc(v, Policy()); }\
|
||||
\
|
||||
template <class T>\
|
||||
inline T modf(const T& v, T* ipart){ using boost::math::modf; return modf(v, ipart, Policy()); }\
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
namespace boost{ namespace math{ namespace detail{
|
||||
|
||||
template <class T, class Policy>
|
||||
inline tools::promote_args_t<T> trunc(const T& v, const Policy& pol, const std::false_type&)
|
||||
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T> trunc(const T& v, const Policy& pol, const std::false_type&)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
@@ -39,20 +39,21 @@ inline tools::promote_args_t<T> trunc(const T& v, const Policy& pol, const std::
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline tools::promote_args_t<T> trunc(const T& v, const Policy&, const std::true_type&)
|
||||
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T> trunc(const T& v, const Policy&, const std::true_type&)
|
||||
{
|
||||
return v;
|
||||
}
|
||||
|
||||
}
|
||||
} // Namespace detail
|
||||
|
||||
template <class T, class Policy>
|
||||
inline tools::promote_args_t<T> trunc(const T& v, const Policy& pol)
|
||||
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T> trunc(const T& v, const Policy& pol)
|
||||
{
|
||||
return detail::trunc(v, pol, std::integral_constant<bool, detail::is_integer_for_rounding<T>::value>());
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline tools::promote_args_t<T> trunc(const T& v)
|
||||
BOOST_MATH_GPU_ENABLED inline tools::promote_args_t<T> trunc(const T& v)
|
||||
{
|
||||
return trunc(v, policies::policy<>());
|
||||
}
|
||||
@@ -70,13 +71,13 @@ inline tools::promote_args_t<T> trunc(const T& v)
|
||||
// https://stackoverflow.com/questions/27442885/syntax-error-with-stdnumeric-limitsmax
|
||||
//
|
||||
template <class T, class Policy>
|
||||
inline int itrunc(const T& v, const Policy& pol)
|
||||
BOOST_MATH_GPU_ENABLED inline int itrunc(const T& v, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
result_type r = boost::math::trunc(v, pol);
|
||||
|
||||
#ifdef BOOST_MATH_HAS_CONSTEXPR_LDEXP
|
||||
#if defined(BOOST_MATH_HAS_CONSTEXPR_LDEXP) && !defined(BOOST_MATH_HAS_GPU_SUPPORT)
|
||||
if constexpr (std::is_arithmetic_v<result_type>
|
||||
#ifdef BOOST_MATH_FLOAT128_TYPE
|
||||
&& !std::is_same_v<BOOST_MATH_FLOAT128_TYPE, result_type>
|
||||
@@ -100,7 +101,7 @@ inline int itrunc(const T& v, const Policy& pol)
|
||||
}
|
||||
}
|
||||
#else
|
||||
static const result_type max_val = ldexp(static_cast<result_type>(1), std::numeric_limits<int>::digits);
|
||||
BOOST_MATH_STATIC_LOCAL_VARIABLE const result_type max_val = ldexp(static_cast<result_type>(1), std::numeric_limits<int>::digits);
|
||||
|
||||
if (r >= max_val || r < -max_val)
|
||||
{
|
||||
@@ -110,20 +111,21 @@ inline int itrunc(const T& v, const Policy& pol)
|
||||
|
||||
return static_cast<int>(r);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline int itrunc(const T& v)
|
||||
BOOST_MATH_GPU_ENABLED inline int itrunc(const T& v)
|
||||
{
|
||||
return itrunc(v, policies::policy<>());
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline long ltrunc(const T& v, const Policy& pol)
|
||||
BOOST_MATH_GPU_ENABLED inline long ltrunc(const T& v, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
result_type r = boost::math::trunc(v, pol);
|
||||
|
||||
#ifdef BOOST_MATH_HAS_CONSTEXPR_LDEXP
|
||||
#if defined(BOOST_MATH_HAS_CONSTEXPR_LDEXP) && !defined(BOOST_MATH_HAS_GPU_SUPPORT)
|
||||
if constexpr (std::is_arithmetic_v<result_type>
|
||||
#ifdef BOOST_MATH_FLOAT128_TYPE
|
||||
&& !std::is_same_v<BOOST_MATH_FLOAT128_TYPE, result_type>
|
||||
@@ -147,7 +149,7 @@ inline long ltrunc(const T& v, const Policy& pol)
|
||||
}
|
||||
}
|
||||
#else
|
||||
static const result_type max_val = ldexp(static_cast<result_type>(1), std::numeric_limits<long>::digits);
|
||||
BOOST_MATH_STATIC_LOCAL_VARIABLE const result_type max_val = ldexp(static_cast<result_type>(1), std::numeric_limits<long>::digits);
|
||||
|
||||
if (r >= max_val || r < -max_val)
|
||||
{
|
||||
@@ -157,20 +159,21 @@ inline long ltrunc(const T& v, const Policy& pol)
|
||||
|
||||
return static_cast<long>(r);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline long ltrunc(const T& v)
|
||||
BOOST_MATH_GPU_ENABLED inline long ltrunc(const T& v)
|
||||
{
|
||||
return ltrunc(v, policies::policy<>());
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline long long lltrunc(const T& v, const Policy& pol)
|
||||
BOOST_MATH_GPU_ENABLED inline long long lltrunc(const T& v, const Policy& pol)
|
||||
{
|
||||
BOOST_MATH_STD_USING
|
||||
using result_type = tools::promote_args_t<T>;
|
||||
result_type r = boost::math::trunc(v, pol);
|
||||
|
||||
#ifdef BOOST_MATH_HAS_CONSTEXPR_LDEXP
|
||||
#if defined(BOOST_MATH_HAS_CONSTEXPR_LDEXP) && !defined(BOOST_MATH_HAS_GPU_SUPPORT)
|
||||
if constexpr (std::is_arithmetic_v<result_type>
|
||||
#ifdef BOOST_MATH_FLOAT128_TYPE
|
||||
&& !std::is_same_v<BOOST_MATH_FLOAT128_TYPE, result_type>
|
||||
@@ -194,7 +197,7 @@ inline long long lltrunc(const T& v, const Policy& pol)
|
||||
}
|
||||
}
|
||||
#else
|
||||
static const result_type max_val = ldexp(static_cast<result_type>(1), std::numeric_limits<long long>::digits);
|
||||
BOOST_MATH_STATIC_LOCAL_VARIABLE const result_type max_val = ldexp(static_cast<result_type>(1), std::numeric_limits<long long>::digits);
|
||||
|
||||
if (r >= max_val || r < -max_val)
|
||||
{
|
||||
@@ -204,21 +207,22 @@ inline long long lltrunc(const T& v, const Policy& pol)
|
||||
|
||||
return static_cast<long long>(r);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
inline long long lltrunc(const T& v)
|
||||
BOOST_MATH_GPU_ENABLED inline long long lltrunc(const T& v)
|
||||
{
|
||||
return lltrunc(v, policies::policy<>());
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename std::enable_if<std::is_constructible<int, T>::value, int>::type
|
||||
BOOST_MATH_GPU_ENABLED inline typename std::enable_if<std::is_constructible<int, T>::value, int>::type
|
||||
iconvert(const T& v, const Policy&)
|
||||
{
|
||||
return static_cast<int>(v);
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename std::enable_if<!std::is_constructible<int, T>::value, int>::type
|
||||
BOOST_MATH_GPU_ENABLED inline typename std::enable_if<!std::is_constructible<int, T>::value, int>::type
|
||||
iconvert(const T& v, const Policy& pol)
|
||||
{
|
||||
using boost::math::itrunc;
|
||||
@@ -226,14 +230,14 @@ inline typename std::enable_if<!std::is_constructible<int, T>::value, int>::type
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename std::enable_if<std::is_constructible<long, T>::value, long>::type
|
||||
BOOST_MATH_GPU_ENABLED inline typename std::enable_if<std::is_constructible<long, T>::value, long>::type
|
||||
lconvert(const T& v, const Policy&)
|
||||
{
|
||||
return static_cast<long>(v);
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename std::enable_if<!std::is_constructible<long, T>::value, long>::type
|
||||
BOOST_MATH_GPU_ENABLED inline typename std::enable_if<!std::is_constructible<long, T>::value, long>::type
|
||||
lconvert(const T& v, const Policy& pol)
|
||||
{
|
||||
using boost::math::ltrunc;
|
||||
@@ -241,14 +245,14 @@ inline typename std::enable_if<!std::is_constructible<long, T>::value, long>::ty
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename std::enable_if<std::is_constructible<long long, T>::value, long long>::type
|
||||
BOOST_MATH_GPU_ENABLED inline typename std::enable_if<std::is_constructible<long long, T>::value, long long>::type
|
||||
llconvertert(const T& v, const Policy&)
|
||||
{
|
||||
return static_cast<long long>(v);
|
||||
}
|
||||
|
||||
template <class T, class Policy>
|
||||
inline typename std::enable_if<!std::is_constructible<long long, T>::value, long long>::type
|
||||
BOOST_MATH_GPU_ENABLED inline typename std::enable_if<!std::is_constructible<long long, T>::value, long long>::type
|
||||
llconvertert(const T& v, const Policy& pol)
|
||||
{
|
||||
using boost::math::lltrunc;
|
||||
|
||||
Reference in New Issue
Block a user