unexpected truncation
Torbjorn Granlund
tg at gmplib.org
Mon Jan 10 17:11:03 CET 2011
daniel yaury <danielyback at gmail.com> writes:
My name is Daniel. I am new to GMP and I have studied the manual.
I have written a simple program to calculate the square root of 2 to
#include <stdio.h>
#include <stdlib.h>
#include <gmp.h>
#define PRECS 128
int main(void)
{
mpf_set_default_prec (PRECS);
mpf_t x;
mpf_init2(x,PRECS);
mpf_sqrt_ui (x,2);
gmp_printf ("fixed point mpf %.*Ff with %d digits\n", PRECS,x , PRECS);
printf("%d\n", mpf_get_default_prec());
mpf_clear(x);
return EXIT_SUCCESS;
}
The output is:
fixed point mpf
1.41421356237309504880168872420969807856900000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
with 128 digits
128
The problem is that SQRT gives less accuracy than I expect it. I believe I
have missed something in the manual.
You seem to be confusing precision in base 2 and precision in base 10.
--
Torbjörn
More information about the gmp-discuss
mailing list