I haven’t been able to find an answer on Wikipedia (or SO) or in the documentation for this very simple question.
How is the precision of a floating point number represented by an integer?
I am using the wrapper MPFRC++ over the arbitrary precision floating point library MPFR in C++. There is the option to set default precision, and it takes an integer as an argument.
What does such an integer mean?
e.g.: set_default_prec(128) .
Also, I check the sizeof for various default precision, but they always seem to be the same? Why?
e.g.:
set_default_prec(128);
sizeof(mpfr::mpreal); // 16
set_default_prec(4096);
sizeof(mpfr::mpreal); // still 16…
set_default_precundoubtedly changes the amount of storage (number of bits) allocated to store the data. It takes about 3.5 bits to store one decimal digit, so from there you just use simple math to figure out how many bytes are needed for a given number of digits.As far as
sizeofremaining constant, you undoubtedly have a struct (or class) that just contains a pointer to the actual data, something on this general order:When you change the precision, it modifies the value stored in num_digits, and possibly the size of the block that
datapoints at, but the size of the structure remains constant.