user42 at zip.com.au
Wed Dec 3 09:17:16 CET 2003
Brian Aker <brian at tangent.org> writes:
> I have an mpf_t value that I would like to output in the form of
> "12323.2344555", so from what I can tell mpf_set_str() is not what I am
> looking for and I am better off using gmp_snprintf(). The problem I am
> running into is that I want to allocate the string for gmp_snprintf()
> correctly before I call it.
> I do not see a method though for doing this (and I dislike the thought
> of calling it twice, and determining if it overflowed or not).
You can pass NULL and 0 to gmp_snprintf to just ask it how big the
output will be, without producing any. I think that works, it ought
But it'll end up doing the output work twice, so you might prefer
gmp_asprintf and copy the result to where you want once you see how
big it is.
More information about the gmp-discuss