问题描述
看来,GMP提供强积金(浮点)的唯一字符串序列化类型:
It seems that GMP provides only string serialization of the mpf (floating point) type:
mpf_get_str()
, mpf_class :: get_str()
在MPZ(整数)类型有原始字节额外的接口: mpz_out_raw()
The mpz (integer) type has an additional interface for raw bytes: mpz_out_raw()
http://gmplib.org/manual/Function-Index.html
我缺少的东西吗?有谁知道,可序列化GMP花车另一个库吗?有谁知道另一个BIGNUM lib中,提供强大的序列化?
Am I missing something? Does anyone know of another library that can serialize GMP floats? Does anyone know of another bignum lib that offers robust serialization?
编辑:我很乐意与序列化MPFR的mpfr_t,以及,这同样似乎只提供字符串输出:http://www.mpfr.org/mpfr-current/mpfr.html#Function-Index
I'd be happy with serializing MPFR's mpfr_t, as well, which similarly only seems to offer string output: http://www.mpfr.org/mpfr-current/mpfr.html#Function-Index
推荐答案
这是很久以前的事,但我清盘做这样的:
This was a long time ago, but I wound up doing something like this:
int mpf_out_raw (FILE *f, mpf_t X) {
int expt; mpz_t Z; size_t nz;
expt = X->_mp_exp;
fwrite(&expt, sizeof(int), 1, f);
nz = X->_mp_size;
Z->_mp_alloc = nz;
Z->_mp_size = nz;
Z->_mp_d = X->_mp_d;
return (mpz_out_raw(f, Z) + sizeof(int));
}
void mpf_inp_raw (FILE *f, mpf_t X) {
int expt; mpz_t Z; size_t nz;
mpz_init (Z);
fread(&expt, sizeof(int), 1, f);
mpz_inp_raw (Z, f);
mpf_set_z (X, Z);
X->_mp_exp = expt;
mpz_clear (Z);
}
这篇关于如何序列化GMP强积金类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!