0

我试图找到一个如何mpfr::mpfr_fac_ui通过互联网使用的例子,但我无法做到,所以我决定在这里问。

我有自己的迭代阶乘

boost::multiprecision::mpfr_float factorial(int start, int end)
{
    boost::multiprecision::mpfr_float fact = 1;

    for (; start <= end; ++start)
        fact *= start;

    return fact;
}

但我想尝试内置factorial

我不知道我做错了什么,因为当我像这样测试它时

mpfr_t test;
mpfr_init2(test, 1000);

std::cout << mpfr_fac_ui(test, 5, MPFR_RNDN) << std::endl;
std::cout << factorial(1, 5) << std::endl;

mpfr_fac_ui不返回任何错误(返回 0)并且test是 0 而它应该是 120。

我做错了什么还是我错过了什么?

4

1 回答 1

1

In C, I get 120 as expected with:

#include <stdio.h>
#include <mpfr.h>

int main (void)
{
  mpfr_t test;
  mpfr_init2 (test, 1000);
  mpfr_fac_ui (test, 5, MPFR_RNDN);
  mpfr_printf ("%Rg\n", test);
  mpfr_clear (test);
  return 0;
}

In your program, you do not show how you print the value of test. All what you do is to print the return value of mpfr_fac_ui, which is 0.

于 2019-05-27T01:52:02.877 回答