Storing and retrieving

Karl Hasselström kha at
Sat Jul 2 12:05:47 CEST 2005

On 2005-07-02 10:31:44 +0200, Hans Aberg wrote:

> At 03:53 +0000 2005/07/02, mrgrynch at wrote:
> > I was thinking the easiest way to do this is with strings. Has
> > anyone done this before?
> One can write binary data to a file and read it back, but I gather
> if the core parts that the GMP relies on would somehow change, it
> would make the file binary data unreadable.

As I wrote in my other mail, GMP has binary IO (or rather
import/export) functions for integers. These work with a well-defined
external format, and so can be relied upon. However, there doesn't
seem to be such a pair of functions for mpf.

Since GMP is free software, you can always use the exact same version
to read the data as you used to write it. You could even read the
source code to find out what the internal representation is, if you
need to do so.

> So the safest way, though slower, is to write it out as text, and
> read it back again. You are then embarking, in its extension, on the
> path of making two programs, a parser that can read this kind of
> data, and an expresser, or "pretty-printer", that can write out it.
> Ultimately, if you develop a computer language, you may need the use
> of tools such as the lexer generator Flex and the parser generator
> Bison.

Or simply use the printf/scanf equivalents that are part of GMP. :-)

Karl Hasselström, kha at
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url :

More information about the gmp-discuss mailing list