Consider the following MCVE:
#include <iostream>
#include <boost/multiprecision/cpp_int.hpp>
int main()
{
boost::multiprecision::cpp_int x = 10;
x *= 10000000000000000000000000000000000000000000000000000000000000;
std::cout<<x<<std::endl;
return 0;
}
It produces a wrong result, due to the obvious overflow from that int
. How can I do this correctly, assuming I don't want to involve strings? Is there something like a "digit shift operator" or a power function that can do this cheaply (or cheapest possible)?
Why? Because I have a fixed-precision library that I wrote, and scaling the internal integer requires such operations to be 100% safe.
Find the example here.
Aucun commentaire:
Enregistrer un commentaire