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_sqrt_ui (x,2);
   gmp_printf ("fixed point mpf %.*Ff with %d digits\n", PRECS,x , PRECS);
   printf("%d\n", mpf_get_default_prec());
   return EXIT_SUCCESS;
  The output is:
  fixed point mpf
  with 128 digits
  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.  


More information about the gmp-discuss mailing list