boostorg / multiprecision

Boost.Multiprecision
Boost Software License 1.0
195 stars 112 forks source link

boost::multiprecision::pow doesn't support cpp_int exponent #588

Closed radj307 closed 8 months ago

radj307 commented 8 months ago

The boost::multiprecision::pow function is missing an overload for using cpp_int as the base and exponent.
Tested on MSVC 19.34.31947 & gcc 10 with boostmp 1.84 standalone.

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

namespace mp = boost::multiprecision;

int main()
{
    using mp::cpp_int;
    using cpp_float = mp::cpp_dec_float_100;

    mp::pow(cpp_float{ 2 }, cpp_float{ 2 }); //< works
    mp::pow(cpp_int{ 2 }, cpp_int{ 2 }); //< ERROR: no matching function for call to ‘pow(boost::multiprecision::cpp_int, boost::multiprecision::cpp_int)’

    return 0;
}
ckormanyos commented 8 months ago

The boost::multiprecision::pow function is missing an overload for using cpp_int

Thanks @radj307 for this observation.

There are several perspectives on this issue. Intuitively, it's not immediately clear to me if an overload for a non-integral type (in the sense of std::is_integral) even should or should not be supported?

Cc: @jzmaddock

jzmaddock commented 8 months ago

This was deliberately not supported: even relatively small integer exponents can blow the result up so large that you will run the machine out of memory, so yes, only native integers are supported as the exponent. powm should be supported for all arguments a cpp_int though.