unexpected truncation

daniel yaury danielyback at gmail.com
Mon Jan 10 14:32:47 CET 2011


Hi Everyone,

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.

I would be glad if someone here can solve the problem so I can get the
accuracy to the specified digit (PRECS in this case)
Thanks,Daniel.


More information about the gmp-discuss mailing list