MPFR Rounding 0.9999 to 1?
- by Silmaersti
I'm attempting to store the value 0.9999 into an mpfr_t variable
But 0.9999 is rounded to 1 (or some other value != 0.9999) during storage, no matter the round value (GMP_RNDD, GMP_RNDU, GMP_RNDN, GMP_RNDZ)
So what's the best method to store 0.9999 in an mpfr_t variable? Is it possible?
Here is my test program, it prints "buffer is: 1", instead of the wanted "buffer is: 0.9999":
int main()
{
size_t precision = 4;
mpfr_t mpfrValue;
mpfr_init2(mpfrValue, precision);
mpfr_set_str(mpfrValue, "0.9999", 10, GMP_RNDN);
char *buffer = (char*)malloc((sizeof(char) * precision) + 3);
mp_exp_t exponent;
mpfr_get_str(buffer,
&exponent,
10,
precision,
mpfrValue,
GMP_RNDN);
printf("buffer is: %s\n", buffer);
free(buffer);
mpfr_clear(mpfrValue);
return 0;
}
Thanks for any help !