I have a problem using GMP (floating point, etc.)

Hans Åberg haberg-1 at telia.com
Mon Sep 7 12:10:31 UTC 2020


> On 7 Sep 2020, at 11:39, Torbjörn Granlund <tg at gmplib.org> wrote:
> 
> The Undertaker <hui_buh666 at yahoo.de> writes:
> 
>  1.) Is it possible to use cin and cout? And how I do that? Because I
>  want to give input and not compile it again, after I have a result and
>  calc the next thing.
> 
> I don't understand this question.
> 
> Are you asking of you can provide mpf_set_str data which is read through
> std::cin instead of from constants?  That's a very basic programming
> question, and this is not the right place for teaching basic
> programming.

This is a gap in in the GMP C interface relative to the C++ language I believe: In C++ one cannot convert a C stream to a C++ stream, even though they now have tied buffers, further tied to the file descriptor on POSIX systems (not reachable from C++ proper).

For output, one can write things like:
  inline std::ostream& operator<<(std::ostream& os, integer const& n) {
    return os << n.str();
  }
But for input, I recall, when I did it long ago, I had to go under the GMP hood, which later broke. I now use Flex to parse into a string and then read that as string in GMP.

My guess is that GMP++ has that as an extension, and that is the reason it requires a separate configuration—all else did not require that when I did it, that is, a header alone suffices.




More information about the gmp-discuss mailing list