2
#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。當我運行該程序,這是我得到:MPFR沒有正確複製數據
Ethans-MacBook-Pro:epi phyrrus9$ ./epi a.txt b.txt
e: 2.7182818284590452353602874713526624977572470936999595749669676277240766303535475945713821785251664274
p: 3.1415926535897932384626433832795028841971693993750806787344699335531291632367535989328301032625839375
e: 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
p: 0.0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
我的問題是,是否有什麼舍入模式我使用什麼問題?因爲第二個e和p不應該是零。
完美,非常感謝! – phyrrus9