#include <boost/math/policies/error_handling.hpp>
#include <boost/math/special_functions/math_fwd.hpp>
#include <boost/math/special_functions/fpclassify.hpp>
-#include <boost/mpl/divides.hpp>
-#include <boost/mpl/plus.hpp>
-#include <boost/mpl/if.hpp>
-#include <boost/type_traits/is_convertible.hpp>
+#include <type_traits>
+#include <cstdint>
namespace boost{ namespace math{
struct big_int_type
{
- operator boost::uintmax_t()const;
+ operator std::uintmax_t() const;
};
-template <class T>
+template <typename T>
struct largest_cbrt_int_type
{
- typedef typename mpl::if_c<
- boost::is_convertible<big_int_type, T>::value,
- boost::uintmax_t,
+ using type = typename std::conditional<
+ std::is_convertible<big_int_type, T>::value,
+ std::uintmax_t,
unsigned int
- >::type type;
+ >::type;
};
-template <class T, class Policy>
+template <typename T, typename Policy>
T cbrt_imp(T z, const Policy& pol)
{
BOOST_MATH_STD_USING
guess = tools::evaluate_polynomial(P, guess);
int i_exp3 = i_exp / 3;
- typedef typename largest_cbrt_int_type<T>::type shift_type;
+ using shift_type = typename largest_cbrt_int_type<T>::type;
- BOOST_STATIC_ASSERT( ::std::numeric_limits<shift_type>::radix == 2);
+ static_assert( ::std::numeric_limits<shift_type>::radix == 2, "The radix of the type to shift to must be 2.");
if(abs(i_exp3) < std::numeric_limits<shift_type>::digits)
{
// checking of the boilerplate version as we know in advance that the function
// is well behaved...
//
- typedef typename policies::precision<T, Policy>::type prec;
- typedef typename mpl::divides<prec, boost::integral_constant<int, 3> >::type prec3;
- typedef typename mpl::plus<prec3, boost::integral_constant<int, 3> >::type new_prec;
- typedef typename policies::normalise<Policy, policies::digits2<new_prec::value> >::type new_policy;
+ using prec = typename policies::precision<T, Policy>::type;
+ constexpr auto prec3 = prec::value / 3;
+ constexpr auto new_prec = prec3 + 3;
+ using new_policy = typename policies::normalise<Policy, policies::digits2<new_prec>>::type;
//
// Epsilon calculation uses compile time arithmetic when it's available for type T,
// otherwise uses ldexp to calculate at runtime:
//
- T eps = (new_prec::value > 3) ? policies::get_epsilon<T, new_policy>() : ldexp(T(1), -2 - tools::digits<T>() / 3);
+ T eps = (new_prec > 3) ? policies::get_epsilon<T, new_policy>() : ldexp(T(1), -2 - tools::digits<T>() / 3);
T diff;
if(original_i_exp < std::numeric_limits<T>::max_exponent - 3)
} // namespace detail
-template <class T, class Policy>
+template <typename T, typename Policy>
inline typename tools::promote_args<T>::type cbrt(T z, const Policy& pol)
{
- typedef typename tools::promote_args<T>::type result_type;
- typedef typename policies::evaluation<result_type, Policy>::type value_type;
+ using result_type = typename tools::promote_args<T>::type;
+ using value_type = typename policies::evaluation<result_type, Policy>::type;
return static_cast<result_type>(detail::cbrt_imp(value_type(z), pol));
}
-template <class T>
+template <typename T>
inline typename tools::promote_args<T>::type cbrt(T z)
{
return cbrt(z, policies::policy<>());