考虑以下代码
// BOGP.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include "gmp-static\gmp.h"
#include <stdlib.h> /* For _MAX_PATH definition */
#include <stdio.h>
#include <malloc.h>
#define F(x) mpf_t x; mpf_init( x );
int main(int argc, char* argv[])
{
F(foo);
char * buff;
mp_exp_t exp;
mpf_init_set_str( foo, "123", 10 );
buff = mpf_get_str(NULL, &exp, 10, 0, foo);
puts( buff );
puts("\n");
free(buff);
mpf_init_set_str( foo, "-123", 10 );
buff = mpf_get_str(NULL, &exp, 10, 0, foo);
puts( buff );
puts("\n");
free(buff);
mpf_init_set_str( foo, "+123", 10 );
buff = mpf_get_str(NULL, &exp, 10, 0, foo);
puts( buff );
puts("\n");
free( buff );
}
在第一个实例中,在 mpf_get_str 调用之后,buff 包含“123”。在第二个中,buff 包含“-123”。但在第三个中,buff 包含一个空字符串(“”)。
这是使用 GMP 4.2.4。也许我需要再次查看手册,但我认为前导“+”会像前导“-”一样容易处理。