Boost logo

Boost Users :

Subject: [Boost-users] multiprecision (/sandbox/big_number/) - pow function
From: Ryan Lichtenwalter (rlichten_at_[hidden])
Date: 2012-05-01 21:37:59


I am using the multiprecision library from /sandbox/big_number
compiling with boost 1.49.0. Specifically, I am using cpp_int.

I can successfully compile and run the following example:

#include <boost/multiprecision/cpp_int.hpp>
using namespace boost::multiprecision;
cpp_int u = 1;
for(unsigned i = 1; i <= 100; ++i)
    u *= i;
std::cout << u << std::endl; // prints 100!

which I obtained from:

https://svn.boost.org/svn/boost/sandbox/big_number/libs/multiprecision/doc/html/boost_multiprecision/tut/ints/cpp_int.html

When I add the following code:

cpp_int x;
x = pow( u, 2 );

I receive the following compiler error (g++ 4.1.2):

./boost/boost/multiprecision/detail/functions/pow.hpp: In function
‘void boost::multiprecision::default_ops::eval_pow(T&, const T&, const
U&) [with T = boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> >, U = int]’:
./boost/boost/multiprecision/detail/default_ops.hpp:1250:
instantiated from ‘void
boost::multiprecision::detail::pow_funct<Backend>::operator()(Backend&,
const Backend&, const Arithmetic&) const [with Arithmetic = int,
Backend = boost::multiprecision::backends::cpp_int_backend<0u, true,
std::allocator<unsigned int> >]’
./boost/boost/multiprecision/mp_number.hpp:1089: instantiated from
‘void boost::multiprecision::mp_number<Backend,
ExpressionTemplates>::do_assign_function_2(const F&, const Exp1&,
const Exp2&, const boost::multiprecision::detail::terminal&, const
boost::multiprecision::detail::terminal&) [with F =
boost::multiprecision::detail::pow_funct<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> > >, Exp1 =
boost::multiprecision::detail::mp_exp<boost::multiprecision::detail::terminal,
boost::multiprecision::mp_number<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> >, true>, void, void>, Exp2 =
boost::multiprecision::detail::mp_exp<boost::multiprecision::detail::terminal,
int, void, void>, Backend =
boost::multiprecision::backends::cpp_int_backend<0u, true,
std::allocator<unsigned int> >, bool ExpressionTemplates = true]’
./boost/boost/multiprecision/mp_number.hpp:1084: instantiated from
‘void boost::multiprecision::mp_number<Backend,
ExpressionTemplates>::do_assign_function(const Exp&, const
mpl_::int_<3>&) [with Exp =
boost::multiprecision::detail::mp_exp<boost::multiprecision::detail::function,
boost::multiprecision::detail::pow_funct<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> > >,
boost::multiprecision::mp_number<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> >, true>, int>, Backend =
boost::multiprecision::backends::cpp_int_backend<0u, true,
std::allocator<unsigned int> >, bool ExpressionTemplates = true]’
./boost/boost/multiprecision/mp_number.hpp:973: instantiated from
‘void boost::multiprecision::mp_number<Backend,
ExpressionTemplates>::do_assign(const Exp&, const
boost::multiprecision::detail::function&) [with Exp =
boost::multiprecision::detail::mp_exp<boost::multiprecision::detail::function,
boost::multiprecision::detail::pow_funct<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> > >,
boost::multiprecision::mp_number<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> >, true>, int>, Backend =
boost::multiprecision::backends::cpp_int_backend<0u, true,
std::allocator<unsigned int> >, bool ExpressionTemplates = true]’
./boost/boost/multiprecision/mp_number.hpp:570: instantiated from
‘void boost::multiprecision::mp_number<Backend,
ExpressionTemplates>::do_assign(const
boost::multiprecision::detail::mp_exp<tag, Arg1, Arg2, Arg3>&, const
mpl_::true_&) [with tag = boost::multiprecision::detail::function,
Arg1 = boost::multiprecision::detail::pow_funct<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> > >, Arg2 =
boost::multiprecision::mp_number<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> >, true>, Arg3 = int, Backend =
boost::multiprecision::backends::cpp_int_backend<0u, true,
std::allocator<unsigned int> >, bool ExpressionTemplates = true]’
./boost/boost/multiprecision/mp_number.hpp:95: instantiated from
‘boost::multiprecision::mp_number<Backend, ExpressionTemplates>&
boost::multiprecision::mp_number<Backend,
ExpressionTemplates>::operator=(const
boost::multiprecision::detail::mp_exp<tag, Arg1, Arg2, Arg3>&) [with
tag = boost::multiprecision::detail::function, Arg1 =
boost::multiprecision::detail::pow_funct<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> > >, Arg2 =
boost::multiprecision::mp_number<boost::multiprecision::backends::cpp_int_backend<0u,
true, std::allocator<unsigned int> >, true>, Arg3 = int, Backend =
boost::multiprecision::backends::cpp_int_backend<0u, true,
std::allocator<unsigned int> >, bool ExpressionTemplates = true]’
vcp_translator_test.cpp:24: instantiated from here
./boost/boost/multiprecision/detail/functions/pow.hpp:89: error:
invalid application of ‘sizeof’ to incomplete type
‘boost::STATIC_ASSERTION_FAILURE<false>’

Different invocations of pow with the arbitrary precision argument as
the base, exponent, or both yield different compiler errors, but all
of them seem to be broken. Am I doing something wrong? Is there some
other fast way to achieve exponentiation with this library?

Thanks,

Ryan


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