Complex/MPC: Start adding non-member functions.

Strip out more unneeded code from mpc.hpp.
This commit is contained in:
jzmaddock
2018-03-10 19:41:01 +00:00
parent e94f507f64
commit c441dca055
3 changed files with 152 additions and 184 deletions

View File

@@ -1817,6 +1817,27 @@ inline typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_
typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
return copysign BOOST_PREVENT_MACRO_SUBSTITUTION(value_type(a), value_type(b));
}
//
// Complex number functions, these are overloaded at the Backend level, we just provide the
// expression template versions here:
//
template <class tag, class A1, class A2, class A3, class A4>
inline typename boost::enable_if_c<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_complex,
typename component_type<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type>::type
real(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
{
typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
return real(value_type(arg));
}
template <class tag, class A1, class A2, class A3, class A4>
inline typename boost::enable_if_c<number_category<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::value == number_kind_complex,
typename component_type<typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type>::type>::type
imag(const multiprecision::detail::expression<tag, A1, A2, A3, A4>& arg)
{
typedef typename multiprecision::detail::expression<tag, A1, A2, A3, A4>::result_type value_type;
return imag(value_type(arg));
}
} // namespace multiprecision
@@ -2686,7 +2707,7 @@ inline typename enable_if_c<number_category<B>::value == number_kind_integer, nu
#define UNARY_OP_FUNCTOR(func, category)\
namespace detail{\
template <class Backend> \
struct BOOST_JOIN(func, _funct)\
struct BOOST_JOIN(category, BOOST_JOIN(func, _funct))\
{\
void operator()(Backend& result, const Backend& arg)const\
{\
@@ -2701,17 +2722,17 @@ template <class tag, class A1, class A2, class A3, class A4> \
inline typename enable_if_c<number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category,\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> > \
>::type \
func(const detail::expression<tag, A1, A2, A3, A4>& arg)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
> (\
detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
, arg \
);\
}\
@@ -2719,17 +2740,17 @@ template <class Backend> \
inline typename enable_if_c<number_category<Backend>::value == category,\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> > \
>::type \
func(const number<Backend, et_on>& arg)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg \
);\
}\
@@ -2748,7 +2769,7 @@ func(const number<Backend, et_off>& arg)\
#define BINARY_OP_FUNCTOR(func, category)\
namespace detail{\
template <class Backend> \
struct BOOST_JOIN(func, _funct)\
struct BOOST_JOIN(category, BOOST_JOIN(func, _funct))\
{\
void operator()(Backend& result, const Backend& arg, const Backend& a)const\
{\
@@ -2774,7 +2795,7 @@ template <class Backend> \
inline typename enable_if_c<number_category<Backend>::value == category,\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, number<Backend, et_on> > \
>::type \
@@ -2782,11 +2803,11 @@ func(const number<Backend, et_on>& arg, const number<Backend, et_on>& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, number<Backend, et_on> \
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg,\
a\
);\
@@ -2796,7 +2817,7 @@ inline typename enable_if_c<\
(number_category<Backend>::value == category) && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, detail::expression<tag, A1, A2, A3, A4> > \
>::type \
@@ -2804,11 +2825,11 @@ func(const number<Backend, et_on>& arg, const detail::expression<tag, A1, A2, A3
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, detail::expression<tag, A1, A2, A3, A4> \
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg,\
a\
);\
@@ -2818,7 +2839,7 @@ inline typename enable_if_c<\
(number_category<Backend>::value == category) && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, detail::expression<tag, A1, A2, A3, A4> \
, number<Backend, et_on> > \
>::type \
@@ -2826,11 +2847,11 @@ func(const detail::expression<tag, A1, A2, A3, A4>& arg, const number<Backend, e
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, detail::expression<tag, A1, A2, A3, A4> \
, number<Backend, et_on> \
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg,\
a\
);\
@@ -2840,7 +2861,7 @@ inline typename enable_if_c<\
(number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category) && (number_category<detail::expression<tagb, A1b, A2b, A3b, A4b> >::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
, detail::expression<tagb, A1b, A2b, A3b, A4b> > \
>::type \
@@ -2848,11 +2869,11 @@ func(const detail::expression<tag, A1, A2, A3, A4>& arg, const detail::expressio
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
, detail::expression<tagb, A1b, A2b, A3b, A4b> \
>(\
detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
, arg,\
a\
);\
@@ -2862,7 +2883,7 @@ inline typename enable_if_c<\
is_arithmetic<Arithmetic>::value && (number_category<Backend>::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, Arithmetic\
> \
@@ -2871,11 +2892,11 @@ func(const number<Backend, et_on>& arg, const Arithmetic& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, Arithmetic\
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg,\
a\
);\
@@ -2885,7 +2906,7 @@ inline typename enable_if_c<\
is_arithmetic<Arithmetic>::value && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
, Arithmetic\
> \
@@ -2894,11 +2915,11 @@ func(const detail::expression<tag, A1, A2, A3, A4>& arg, const Arithmetic& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
, Arithmetic\
>(\
detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
, arg,\
a\
);\
@@ -2908,7 +2929,7 @@ inline typename enable_if_c<\
is_arithmetic<Arithmetic>::value && (number_category<Backend>::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, Arithmetic \
, number<Backend, et_on> \
> \
@@ -2917,11 +2938,11 @@ func(const Arithmetic& arg, const number<Backend, et_on>& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, Arithmetic \
, number<Backend, et_on> \
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg,\
a\
);\
@@ -2931,7 +2952,7 @@ inline typename enable_if_c<\
is_arithmetic<Arithmetic>::value && (number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, Arithmetic \
, detail::expression<tag, A1, A2, A3, A4> \
> \
@@ -2940,11 +2961,11 @@ func(const Arithmetic& arg, const detail::expression<tag, A1, A2, A3, A4>& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, Arithmetic \
, detail::expression<tag, A1, A2, A3, A4> \
>(\
detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
, arg,\
a\
);\
@@ -2993,7 +3014,7 @@ inline typename enable_if_c<\
(number_category<detail::expression<tag, A1, A2, A3, A4> >::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
, Arg2> \
>::type \
@@ -3001,11 +3022,11 @@ func(const detail::expression<tag, A1, A2, A3, A4>& arg, Arg2 const& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type> \
, detail::expression<tag, A1, A2, A3, A4> \
, Arg2\
>(\
detail::BOOST_JOIN(func, _funct)<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<typename detail::backend_type<detail::expression<tag, A1, A2, A3, A4> >::type>() \
, arg, a \
);\
}\
@@ -3014,7 +3035,7 @@ inline typename enable_if_c<\
(number_category<Backend>::value == category),\
detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, Arg2> \
>::type \
@@ -3022,11 +3043,11 @@ func(const number<Backend, et_on>& arg, Arg2 const& a)\
{\
return detail::expression<\
detail::function\
, detail::BOOST_JOIN(func, _funct)<Backend> \
, detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend> \
, number<Backend, et_on> \
, Arg2\
>(\
detail::BOOST_JOIN(func, _funct)<Backend>() \
detail::BOOST_JOIN(category, BOOST_JOIN(func, _funct))<Backend>() \
, arg,\
a\
);\
@@ -3046,7 +3067,7 @@ func(const number<Backend, et_off>& arg, Arg2 const& a)\
#define HETERO_BINARY_OP_FUNCTOR(func, Arg2, category)\
namespace detail{\
template <class Backend> \
struct BOOST_JOIN(func, _funct)\
struct BOOST_JOIN(category, BOOST_JOIN(func, _funct))\
{\
template <class Arg>\
void operator()(Backend& result, Backend const& arg, Arg a)const\
@@ -3165,12 +3186,27 @@ HETERO_BINARY_OP_FUNCTOR_B(scalbln, long, number_kind_floating_point)
HETERO_BINARY_OP_FUNCTOR_B(scalbn, boost::long_long_type, number_kind_floating_point)
HETERO_BINARY_OP_FUNCTOR_B(scalbln, boost::long_long_type, number_kind_floating_point)
//
// Complex functions:
//
UNARY_OP_FUNCTOR(exp, number_kind_complex)
UNARY_OP_FUNCTOR(log, number_kind_complex)
UNARY_OP_FUNCTOR(log10, number_kind_complex)
BINARY_OP_FUNCTOR(pow, number_kind_complex)
UNARY_OP_FUNCTOR(sqrt, number_kind_complex)
UNARY_OP_FUNCTOR(sin, number_kind_complex)
UNARY_OP_FUNCTOR(cos, number_kind_complex)
UNARY_OP_FUNCTOR(tan, number_kind_complex)
UNARY_OP_FUNCTOR(asin, number_kind_complex)
UNARY_OP_FUNCTOR(acos, number_kind_complex)
UNARY_OP_FUNCTOR(atan, number_kind_complex)
//
// Integer functions:
//
BINARY_OP_FUNCTOR(gcd, number_kind_integer)
BINARY_OP_FUNCTOR(lcm, number_kind_integer)
HETERO_BINARY_OP_FUNCTOR_B(pow, unsigned, number_kind_integer)
HETERO_BINARY_OP_FUNCTOR(pow, unsigned, number_kind_integer)
#undef BINARY_OP_FUNCTOR
#undef UNARY_OP_FUNCTOR

View File

@@ -781,7 +781,7 @@ inline typename enable_if_c<is_convertible<V, number<mpfr_float_backend<Digits10
template <unsigned Digits10>
inline void eval_sqrt(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val)
{
mpc_sqrt(result.data(), val.data());
mpc_sqrt(result.data(), val.data(), GMP_RNDN);
}
template <unsigned Digits10>
@@ -790,191 +790,64 @@ inline void eval_abs(mpc_float_backend<Digits10>& result, const mpc_float_backen
mpc_abs(result.data(), val.data());
}
template <unsigned Digits10>
inline void eval_fabs(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val)
{
mpc_abs(result.data(), val.data());
}
template <unsigned Digits10>
inline void eval_ceil(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val)
{
mpfr_float_backend<Digits10> a, b;
mpfr_set(a.data(), val.left_data(), GMP_RNDN);
mpfr_set(b.data(), val.right_data(), GMP_RNDN);
eval_ceil(a, a);
eval_ceil(b, b);
if(a.compare(b) != 0)
{
BOOST_THROW_EXCEPTION(interval_error("Attempt to take the ceil of a value that straddles an integer boundary."));
}
mpc_set_fr(result.data(), a.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_floor(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val)
{
mpfr_float_backend<Digits10> a, b;
mpfr_set(a.data(), val.left_data(), GMP_RNDN);
mpfr_set(b.data(), val.right_data(), GMP_RNDN);
eval_floor(a, a);
eval_floor(b, b);
if(a.compare(b) != 0)
{
BOOST_THROW_EXCEPTION(interval_error("Attempt to take the floor of a value that straddles an integer boundary."));
}
mpc_set_fr(result.data(), a.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_ldexp(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val, long e)
{
if(e > 0)
mpc_mul_2exp(result.data(), val.data(), e);
else if(e < 0)
mpc_div_2exp(result.data(), val.data(), -e);
else
result = val;
}
template <unsigned Digits10>
inline void eval_frexp(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val, int* e)
{
mpfr_float_backend<Digits10> t, rt;
mpc_mid(t.data(), val.data());
eval_frexp(rt, t, e);
eval_ldexp(result, val, -*e);
}
template <unsigned Digits10>
inline void eval_frexp(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& val, long* e)
{
mpfr_float_backend<Digits10> t, rt;
mpc_mid(t.data(), val.data());
eval_frexp(rt, t, e);
eval_ldexp(result, val, -*e);
}
template <unsigned Digits10>
inline int eval_fpclassify(const mpc_float_backend<Digits10>& val) BOOST_NOEXCEPT
{
return mpc_inf_p(val.data()) ? FP_INFINITE : mpc_nan_p(val.data()) ? FP_NAN : mpc_is_zero(val.data()) ? FP_ZERO : FP_NORMAL;
}
template <unsigned Digits10>
inline void eval_pow(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& b, const mpc_float_backend<Digits10>& e)
{
typedef typename boost::multiprecision::detail::canonical<unsigned, mpc_float_backend<Digits10> >::type ui_type;
using default_ops::eval_get_sign;
int s = eval_get_sign(b);
if(s == 0)
{
if(eval_get_sign(e) == 0)
{
result = ui_type(1);
}
else
{
result = ui_type(0);
}
return;
}
if(s < 0)
{
if(eval_get_sign(e) < 0)
{
mpc_float_backend<Digits10> t1, t2;
t1 = e;
t1.negate();
eval_pow(t2, b, t1);
t1 = ui_type(1);
eval_divide(result, t1, t2);
return;
}
typename boost::multiprecision::detail::canonical<boost::uintmax_t, mpc_float_backend<Digits10> >::type an;
#ifndef BOOST_NO_EXCEPTIONS
try
{
#endif
using default_ops::eval_convert_to;
eval_convert_to(&an, e);
if(e.compare(an) == 0)
{
mpc_float_backend<Digits10> pb(b);
pb.negate();
eval_pow(result, pb, e);
if(an & 1u)
result.negate();
return;
}
#ifndef BOOST_NO_EXCEPTIONS
}
catch(const std::exception&)
{
// conversion failed, just fall through, value is not an integer.
}
#endif
result = std::numeric_limits<number<mpc_float_backend<Digits10>, et_on> >::quiet_NaN().backend();
return;
}
mpc_log(result.data(), b.data());
mpc_mul(result.data(), result.data(), e.data());
mpc_exp(result.data(), result.data());
mpc_pow(result.data(), b.data(), e.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_exp(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_exp(result.data(), arg.data());
}
template <unsigned Digits10>
inline void eval_exp2(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_exp2(result.data(), arg.data());
mpc_exp(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_log(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_log(result.data(), arg.data());
mpc_log(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_log10(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_log10(result.data(), arg.data());
mpc_log10(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_sin(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_sin(result.data(), arg.data());
mpc_sin(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_cos(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_cos(result.data(), arg.data());
mpc_cos(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_tan(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_tan(result.data(), arg.data());
mpc_tan(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_asin(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_asin(result.data(), arg.data());
mpc_asin(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_acos(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_acos(result.data(), arg.data());
mpc_acos(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
inline void eval_atan(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_atan(result.data(), arg.data());
mpc_atan(result.data(), arg.data(), GMP_RNDN);
}
template <unsigned Digits10>
@@ -1001,12 +874,6 @@ inline void eval_tanh(mpc_float_backend<Digits10>& result, const mpc_float_backe
mpc_tanh(result.data(), arg.data());
}
template <unsigned Digits10>
inline void eval_log2(mpc_float_backend<Digits10>& result, const mpc_float_backend<Digits10>& arg)
{
mpc_log2(result.data(), arg.data());
}
template <unsigned Digits10>
inline std::size_t hash_value(const mpc_float_backend<Digits10>& val)
{

View File

@@ -157,6 +157,7 @@ typename boost::enable_if_c<boost::multiprecision::number_category<Real>::value
Real z(1);
int cr = a < b ? -1 : a > b ? 1 : 0;
(void)cr;
BOOST_CHECK_EQUAL(r1 == r2, a == b);
BOOST_CHECK_EQUAL(r1 != r2, a != b);
@@ -1955,6 +1956,70 @@ typename boost::enable_if_c<boost::multiprecision::number_category<Real>::value
BOOST_CHECK_EQUAL(c.real(), 2);
BOOST_CHECK_EQUAL(c.imag(), 3);
BOOST_CHECK_EQUAL(real(a), 30);
BOOST_CHECK_EQUAL(imag(a), 0);
BOOST_CHECK_EQUAL(real(c), 2);
BOOST_CHECK_EQUAL(imag(c), 3);
BOOST_CHECK_EQUAL(real(a + 0), 30);
BOOST_CHECK_EQUAL(imag(a + 0), 0);
BOOST_CHECK_EQUAL(real(c + 0), 2);
BOOST_CHECK_EQUAL(imag(c + 0), 3);
typedef typename boost::multiprecision::component_type<Real>::type real_type;
real_type r(3);
real_type tol = std::numeric_limits<real_type>::epsilon() * 30;
a = r;
BOOST_CHECK_EQUAL(real(a), 3);
BOOST_CHECK_EQUAL(imag(a), 0);
a = exp(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("-7.3151100949011025174865361510507893218698794489446322367845159660828327860599907104337742108443234172141249777"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.0427436562359044141015039404625521939183300604422348975424523449538886779880818796291971422701951470533151185"), imag(a), tol);
a = log(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.282474678730768368026743720782659302402633972380103558209522755331732333662205089699787331720244744384629096046"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("0.9827937232473290679857106110146660144968774536316285567614250883179880715497960353897065343728173111081651397020"), imag(a), tol);
a = log10(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("0.556971676153418384603252578971164215414864594193534135900595487498776545815097120403823727129449829836488977743"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("0.426821890855466638944275673291166123449562356934437957244904971730668088711719757900679614536803436424488603794"), imag(a), tol);
b = Real(5, -2);
a = pow(c, b);
BOOST_CHECK_CLOSE_FRACTION(real_type("-3053.8558566606567369633610140423321260211388217942246293871310470377722279440084474789529228008638668934381183"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("3097.9975862915005132449772136982559285192410496951232473245540634244845290672745578327467396750607773968246915"), imag(a), tol);
a = pow(c, 3);
BOOST_CHECK_CLOSE_FRACTION(real_type(-46), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type(9), imag(a), tol);
a = pow(3, c);
BOOST_CHECK_CLOSE_FRACTION(real_type("-8.8931513442797186948734782808862447235385767991868219480917324534839621090167050538805196124711247247992169338"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("-1.3826999557878897572499699021550296885662132089951379549068064961882821777067532977546360861176011175070188118"), imag(a), tol);
//TODO powers where one arg is a real_type.
a = sqrt(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.674149228035540040448039300849051821674708677883920366727287836003399240343274891876712629708287692163156802065"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("0.8959774761298381247157337552900434410433241995549314932449006989874470582160955817053273057885402621549320588976"), imag(a), tol);
a = sin(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("9.154499146911429573467299544609832559158860568765182977899828142590020335321896403936690014669532606510294425039"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("-4.168906959966564350754813058853754843573565604758055889965478710592666260138453299795649308385497563475115931624"), imag(a), tol);
a = cos(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("-4.1896256909688072301325550196159737286219454041279210357407905058369727912162626993926269783331491034500484583"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("-9.1092278937553365979791972627788621213326202389201695649104967309554222940748568716960841549279996556547993373"), imag(a), tol);
a = tan(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("-0.0037640256415042482927512211303226908396306202016580864328644932511249097100916559688254811519914564480500042311"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.0032386273536098014463585978219272598077897241071003399272426939850671219193120708438426543945017427085738411"), imag(a), tol);
a = asin(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("0.5706527843210994007102838796856696501828032450960401365302732598209740064262509342420347149436326252483895113827"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.983387029916535432347076902894039565014248302909345356125267430944752731616095111727103650117987412058949254132"), imag(a), tol);
a = acos(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.000143542473797218521037811954081791915781454591512773957199036332934196716853565071982697727425908742684531873"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("-1.983387029916535432347076902894039565014248302909345356125267430944752731616095111727103650117987412058949254132"), imag(a), tol);
a = atan(c);
BOOST_CHECK_CLOSE_FRACTION(real_type("1.409921049596575522530619384460420782588207051908724814771070766475530084440199227135813201495737846771570458568"), real(a), tol);
BOOST_CHECK_CLOSE_FRACTION(real_type("0.2290726829685387662958818029420027678625253049770656169479919704951963414344907622560676377741902308144912055002"), imag(a), tol);
}
template <class Real>