-2

我们在数据类型方面遇到了严重问题。我对 c++ 中的数据类型有很大的问题。我必须处理 100 位数字。我一直在尝试使用 mpfr real,但编译器总是崩溃。

#include <iostream>
#include <gmp.h>
#include <mpfr.h>

mpfr::real Modulo(mpfr::mpreal number);

int main()
{
  mpfr::mpreal test, number;
  number = 3.14159;
  mpfr::mpreal::getPrecision(500)
  mpfr::mpreal  a = "-1";
  mpfr::mpreal  prime = "57896044618658097711785492504343953926634992332820282019728792003956564819949";
  mpfr::mpreal  d = "-121665/121666";

  test=Modulo(number);

}

mpfr::mpreal:: Modulo(mpfr::mpreal number)
{
 extern mpfr::mpreal a , d, prime;
 a = d;
 std::cout << prime;
 return number;
}

这只是某种评价。系统找不到 mpfr 的声明 /"mpfr is not a type" 安装了库。

错误信息:

/home/tamwyn/evaluate/main.cpp|5|error: ‘mpfr’ does not name a type|
/home/tamwyn/evaluate/main.cpp||In function ‘int main()’:|
/home/tamwyn/evaluate/main.cpp|6|error: ‘mpfr’ has not been declared|
/home/tamwyn/evaluate/main.cpp|6|error: expected ‘;’ before ‘test’|
/home/tamwyn/evaluate/main.cpp|7|error: ‘number’ was not declared in this scope|
/home/tamwyn/evaluate/main.cpp|8|error: ‘mpfr’ has not been declared|
/home/tamwyn/evaluate/main.cpp|9|error: expected ‘;’ before ‘mpfr’|
/home/tamwyn/evaluate/main.cpp|10|error: ‘mpfr’ has not been declared|
/home/tamwyn/evaluate/main.cpp|10|error: expected ‘;’ before ‘prime’|
/home/tamwyn/evaluate/main.cpp|11|error: ‘mpfr’ has not been declared|
/home/tamwyn/evaluate/main.cpp|11|error: expected ‘;’ before ‘d’|
/home/tamwyn/evaluate/main.cpp|13|error: ‘test’ was not declared in this scope|
/home/tamwyn/evaluate/main.cpp|13|error: ‘Modulo’ was not declared in this scope|
/home/tamwyn/evaluate/main.cpp|17|error: ‘mpfr’ does not name a type|
||=== Build finished: 13 errors, 0 warnings ===|

真实的.hpp:

#include <iostream>
#include <gmp.h>
#include "real.hpp"

  mpfr::real test, number;
  number = 3.14159;
  mpfr::real::getPrecision(500)
  mpfr::real  a = "-1";
  mpfr::real  prime = "57896044618658097711785492504343953926634992332820282019728792003956564819949";
  mpfr::real  d = "-121665/121666";

与另一个示例中的结构相同,但现在有另一个声明和更多错误:

Compiling: main.cpp
/home/tamwyn/evaluate/main.cpp:5:1: error: invalid use of template-name ‘mpfr::real’ without an argument list
/home/tamwyn/evaluate/main.cpp: In function ‘int main()’:
/home/tamwyn/evaluate/main.cpp:9:14: error: missing template arguments before ‘test’
/home/tamwyn/evaluate/main.cpp:9:14: error: expected ‘;’ before ‘test’
/home/tamwyn/evaluate/main.cpp:10:3: error: ‘number’ was not declared in this scope
/home/tamwyn/evaluate/main.cpp:11:9: error: ‘template<long int _prec, mpfr_rnd_t _rnd> class mpfr::real’ used without template parameters
/home/tamwyn/evaluate/main.cpp:12:3: error: expected ‘;’ before ‘mpfr’
/home/tamwyn/evaluate/main.cpp:13:15: error: missing template arguments before ‘prime’
/home/tamwyn/evaluate/main.cpp:13:15: error: expected ‘;’ before ‘prime’
/home/tamwyn/evaluate/main.cpp:14:15: error: missing template arguments before ‘d’
/home/tamwyn/evaluate/main.cpp:14:15: error: expected ‘;’ before ‘d’
/home/tamwyn/evaluate/main.cpp:16:3: error: ‘test’ was not declared in this scope
/home/tamwyn/evaluate/main.cpp:16:21: error: ‘Modulo’ was not declared in this scope
/home/tamwyn/evaluate/main.cpp: At global scope:
/home/tamwyn/evaluate/main.cpp:20:1: error: invalid use of template-name ‘mpfr::real’ without an argument list

你有什么建议可以使用哪种类型来处理这样和更长的数字吗?我为 mpfr 找到了几个,但总是遇到同样的问题。

4

1 回答 1

0

mpfr::real使用#include <real.hpp>

于 2015-05-19T14:39:41.540 回答