Boost logo

Boost Users :

Subject: Re: [Boost-users] Cpp_int and cpp_dec_float conversion
From: John Maddock (john_at_[hidden])
Date: 2013-04-24 03:49:18


>is there a way to convert from cpp_int to cpp_dec_float and viceversa?
>
>Since I've to use the modulus between two cpp_dec_float which I know
>they're integers but I need sqrt before and trying to run % with them
>gives:

You could use fmod in place of the % operator?

There is an explicit conversion from cpp_int to cpp_dec_float, but no
conversion in the opposite direction (in general it's unsafe). I guess we
should try and figure out a generic way to implement the equivalent of
iround/itrunc for that.

/usr/local/include/boost/multiprecision/number.hpp: In member function
> ‘void boost::multiprecision::number<Backend,
> ExpressionTemplates>::do_assign(const Exp&, const
> boost::multiprecision::detail::modulus_immediates&) [with Exp =
> boost::multiprecision::detail::expression<boost::multiprecision::detail::modulus_immediates,
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>,
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, void, void>, Backend =
> boost::multiprecision::backends::cpp_dec_float<100u, int, void>,
> boost::multiprecision::expression_template_option ExpressionTemplates =
> et_on]’:
> /usr/local/include/boost/multiprecision/number.hpp:680: instantiated
> from ‘void boost::multiprecision::number<Backend,
> ExpressionTemplates>::do_assign(const
> boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>&,
> const mpl_::true_&) [with tag =
> boost::multiprecision::detail::modulus_immediates, Arg1 =
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, Arg2 =
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, Arg3 = void, Arg4 = void, Backend =
> boost::multiprecision::backends::cpp_dec_float<100u, int, void>,
> boost::multiprecision::expression_template_option ExpressionTemplates =
> et_on]’
> /usr/local/include/boost/multiprecision/number.hpp:134: instantiated
> from ‘typename boost::enable_if<boost::is_convertible<typename
> boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3,
> Arg4>::result_type, boost::multiprecision::number<Backend,
> ExpressionTemplates> >, boost::multiprecision::number<Backend,
> ExpressionTemplates>&>::type boost::multiprecision::number<Backend,
> ExpressionTemplates>::operator=(const
> boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>&)
> [with tag = boost::multiprecision::detail::modulus_immediates, Arg1 =
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, Arg2 =
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, Arg3 = void, Arg4 = void, Backend =
> boost::multiprecision::backends::cpp_dec_float<100u, int, void>,
> boost::multiprecision::expression_template_option ExpressionTemplates =
> et_on]’
> /usr/local/include/boost/multiprecision/number.hpp:181: instantiated
> from ‘boost::multiprecision::number<Backend,
> ExpressionTemplates>::number(const
> boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3, Arg4>&,
> typename boost::enable_if_c<boost::is_convertible<typename
> boost::multiprecision::detail::expression<tag, Arg1, Arg2, Arg3,
> Arg4>::result_type,boost::multiprecision::number<Backend,
> ExpressionTemplates> >::value, void>::type*) [with tag =
> boost::multiprecision::detail::modulus_immediates, Arg1 =
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, Arg2 =
> boost::multiprecision::number<boost::multiprecision::backends::cpp_dec_float<100u,
> int, void>, et_on>, Arg3 = void, Arg4 = void, Backend =
> boost::multiprecision::backends::cpp_dec_float<100u, int, void>,
> boost::multiprecision::expression_template_option ExpressionTemplates =
> et_on]’
> test.cpp:20: instantiated from here
> /usr/local/include/boost/multiprecision/number.hpp:912: error: invalid
> application of ‘sizeof’ to incomplete type
> ‘boost::STATIC_ASSERTION_FAILURE<false>’

Uh. That's a horrible message :-( I'll see if there's a way to make that
any better.

Regards, John.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net