2

everyone

I want to use mpfr_sum function to get the sum of a mpfr_t array, but I don't know how to get mpfr_ptr from mpfr_t. The following is a example:

mpfr_t sum, v[100];
mpfr_init2(sum, 512)
for(int i = 0; i < 100; ++i) mpfr_init2(v[i], 512);
// do something
// how to use mpfr_sum to get sum of array v?
// int mpfr_sum (mpfr_t rop, const mpfr_ptr tab[], unsigned long int n, mpfr_rnd_t rnd)

Please give me a hint, thanks in advance.

1 Answers1

1

You need to assign v[i] to a mpfr_ptr. For instance:

  mpfr_t sum, v[100];
  mpfr_ptr vp[100];

  mpfr_init2 (sum, 512);
  for (int i = 0; i < 100; i++)
    {
      mpfr_init2 (v[i], 512);
      vp[i] = v[i];
    }

Then, after setting values in v[i]:

  mpfr_sum (sum, vp, 100, MPFR_RNDN);
vinc17
  • 2,829
  • 17
  • 23
  • Thank you. it works, and I found mpfr_ptr and mpfr_t variables should be declared in the same domain. Otherwise, a core dump error occurs. – Wei WeiDeng Aug 11 '21 at 03:06