It seems that you're looking for mpf_class::get_str()
, which will break up the floating-point value 1.234
into the string "1234"
and the exponent 1
, because 1.234 == 0.1234 * 10^1
You will need to subtract the size of the string from that exponent, to fit your requirements.
#include <iostream>
#include <string>
#include <gmpxx.h>
int main()
{
double a = 1.125; // 1.234 cannot be stored in a double exactly, try "1.234"
mpf_class f(a);
mp_exp_t exp;
std::string significand = f.get_str(exp);
std::cout << "significand = " << significand
<< " exponent = " << exp-(int)significand.size() << '\n';
}
This prints
~ $ ./test
significand = 1125 exponent = -3