MPFR not copying data correctly

111 views Asked by At
#include <stdio.h>
#include <gmp.h>
#include <mpfr.h>
#include <stdlib.h>
#include <math.h>
#include <limits.h>

mpf_t epi;

int main(int argc, char * * argv)
{
    mpf_t e;
    mpf_t pi;
    mpfr_t er;
    mpfr_t pir;
    FILE *a;
    FILE *b;

    a = fopen(argv[1], "r");
    b = fopen(argv[2], "r");
    mpf_set_default_prec(1024048);
    mpf_init(e);
    mpf_init(pi);
    mpfr_set_default_prec(1024048);
    mpfr_init(er);
    mpfr_init(pir);

    gmp_fscanf(a, "%Ff", &e);
    gmp_fscanf(b, "%Ff", &pi);
    fclose(a);
    fclose(b);

    mpfr_set_f(er, e, GMP_RNDN);
    mpfr_set_f(pir, pi, GMP_RNDN);

    gmp_printf("e: %.100Ff\np: %.100Ff\n", e, pi);
    mpfr_printf("e: %.100Ff\np: %.100Ff\n", er, pir);

}

The code all seems to be correct, and it should copy e to er and pi to pir. When I run the program, this is what I get:

Ethans-MacBook-Pro:epi phyrrus9$ ./epi a.txt b.txt 
e: 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
p: 3.1415926535897932384626433832795028841971693993750806787344699335531291632367535989328301032625839375
e: 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
p: 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

My question is, is there some issue with what rounding mode I am using or something? Because the second e and p should not be zero.

1

There are 1 answers

0
MvG On BEST ANSWER

The copying works fine, it's the printing which is broken.

If you look at 5.9.2 in the manual, you will find that a mpfr_t value should be specified using %Rf, not %Ff which is reserved for mpf_t.