Saving GMP mpf_t variables to binary files (Martins)
Jim White
mathimagics at yahoo.co.uk
Fri Jul 6 13:29:42 CEST 2007
Binary IO is certainly the way to do it, but you need
to write your own "mpf_save" and "mpf_load" routines.
I have such routines, but alas they are not yet ported
to C (they are in Visual Basic).
But the idea is simple - look at the internal
representation (manual section 17.3) - saving is just
writing the ._mp_size and ._mp_exp fields, followed by
the block of limbs, whose address is given by the
._mp_d field, and whose size in words is given by
abs(._mp_size)
To "load", you read in the ._mp_size field, then make
sure your receiving var has sufficient limb
allocation, then load the limb data directly into the
limb array, or into an intermediate array from which
you can use memcpy to copy it into the limb array.
Cheers
Jim White
ANU
More information about the gmp-discuss
mailing list