First, the expression
pow(112.2, 3.4)
will call the double, double overload of std::pow. If you want to call boost::multiprecision::pow instead, you need to have arguments of a type it understands, such as cpp_dec_float_50 or cpp_dec_float_100. Let's also bump the output precision:
1 2 3 4 5 6 7
|
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>
using boost::multiprecision::cpp_dec_float_100;
int main() {
cpp_dec_float_100 a = 112.2, b = 3.4;
std::cout << std::setprecision(100) << pow(a, b) << '\n';
}
|
that prints
9332021.131197257591348458922719177023364501846775209425573316488942730002711710486442926388398457225
|
live demo:
https://wandbox.org/permlink/tsy1Fv39kbpyJylr
Second, you want to work with high-precision math, but you're losing it right away:
the expression
112.2
is not 112 and two-tenths. It is a
double
with the value 112.2000000000000028421709430404007434844970703125. Likewise, "3.4" in a C++ program is not three and four-tenths, it is 3.399999999999999911182158029987476766109466552734375
So, fixing these issues,
1 2 3 4 5 6 7 8
|
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <iostream>
using boost::multiprecision::cpp_dec_float_100;
int main() {
auto a = cpp_dec_float_100(1122)/10;
auto b = cpp_dec_float_100(34)/10;
std::cout << std::setprecision(100) << pow(a, b) << '\n';
}
|
live:
https://wandbox.org/permlink/86pIHR2prfIPHpLb
9332021.131197260700021602241138475068619624389028454081951744553393671746470878427399406755645506478 |
to compare, wolfram alpha for 112.2^3.4 prints
9.332021131197260700021602241138475068619624389028454081951744553393671746470878427399406755645506475578676563... × 10^6
which matches the second result to its second-to-last digit
Nearly all digits of the first result had nothing to do with 112.2^3.4