#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);
}
代码似乎都是正确的,它应该将e复制到er和pi复制到pir。当我运行程序时,这就是我得到的:
Ethans-MacBook-Pro:epi phyrrus9$ ./epi a.txt b.txt
e: 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
p: 3.1415926535897932384626433832795028841971693993750806787344699335531291632367535989328301032625839375
e: 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
p: 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
我的问题是,我使用的舍入模式有什么问题吗?因为第二个e和p不应该为零。