mpf_t precision problem?

Randall randallrathbun at gmail.com
Mon Mar 22 18:15:04 CET 2010


Dear gmp bug-list moderator:

The problem with the gmp++ class mpf_class appears to be down inside the 
mpf_t itself.  I wrote a pure C program, but it is exhibiting the exact 
same problems, perhaps worse.

--------- example.c ----------------------
#include <stdio.h>
#include <gmp.h>

int main(void) {

  mpf_set_default_prec(220);

  char value[214] = 
{"0.0123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890"};
  value[214] = '\0';

  printf("value = %s\n",value);

  mpf_t tiny,reciprocal,one,eightyone;

  mpf_init2(tiny,220);
  mpf_init2(reciprocal,220);
  mpf_init2(one,220);
  mpf_init2(eightyone,220);

  mpf_set_str(tiny,value,10);
  mpf_set_ui(one,1);
  mpf_set_ui(eightyone,81);

  gmp_printf("one = %.*Ff\n",211,one);
  gmp_printf("eightyone = %.*Ff\n",211,eightyone);

  gmp_printf("tiny  = %.*Ff\n",211,tiny);

  mpf_div(reciprocal,one,eightyone); /* reciprocal = 1 / 81 */

  gmp_printf("reciprocal = %.*F\n",211,reciprocal);

  mpf_clear(tiny);
  mpf_clear(reciprocal);
  mpf_clear(one);
  mpf_clear(eightyone);

  return 0;
}
---------- end example.c -------------------
compiled by "gcc example.c -lgmp

reciprocal should have returned the value = 
0.0123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123456790123...

Randall



More information about the gmp-bugs mailing list