-2

We are having heavy issues with data types. I have huge problem with data types in c++. I have to handle numbers with 100 digits. I've been trying to use mpfr real, but the compiler crashs always.

#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;
}

This is just some kind of evaluation. The system isn't able to find a declaration of mpfr /"mpfr is not a type" The Libraries are installed.

Error messages:

/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 ===|

real.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";

The same structure as in the other example but now with another declaration and way more errors:

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

Do you have any advice which type to use for numbers like this and longer? I found several for mpfr but had always the same issues.

Andrew T.
  • 4,701
  • 8
  • 43
  • 62
Tamwyn
  • 312
  • 4
  • 16
  • I doubt the compiler "crashs", I bet it gives you specific errors. Could you share the exact error messages? – Cory Kramer May 19 '15 at 14:10
  • 3
    Can you please try to create a [Minimal, Complete, and Verifiable Example](http://stackoverflow.com/help/mcve) containing the problems you have, edit your question to include that. Can you also please include the *exact*, *complete* and *unmodified* error output for the code in the question? – Some programmer dude May 19 '15 at 14:14
  • 2
    Also please provide what compiler you are using and how you are compiling. – NathanOliver May 19 '15 at 14:19
  • Im using the gnu gcc compiler (g++ on ubuntu) The compiler is called by codeblocks. – Tamwyn May 19 '15 at 14:26
  • 1
    mpfr.h does not contain a mpfr namespace. It looks like you want to include [`real.hpp`](http://chschneider.eu/programming/mpfr_real/) instead. [mpfr](http://www.mpfr.org/) – David Ruhmann May 19 '15 at 14:36
  • I've tried this, well it leaves me back with more errors than before. I will post them separately – Tamwyn May 19 '15 at 14:41

1 Answers1

0

for mpfr::real use #include <real.hpp>

David Ruhmann
  • 11,064
  • 4
  • 37
  • 47
  • I used this example, i will try to start up from scartch with the example again today in the evening und update the page again if I have results, or at least close it Thanks for the help. – Tamwyn May 19 '15 at 14:48