GMP can't handle leading plus sign?
Bruce M. Axtens
bruce.axtens at gmail.com
Mon Jan 19 08:53:30 CET 2009
Consider the following code
// 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 );
}
In the first instance, after the mpf_get_str call, buff contains "123".
In the second, buff contains "-123".
But in the third, buff contains an empty string ("").
This is using GMP 4.2.4. Maybe I need to look in the manual again, but I
would have thought that a leading "+" would have been handled as readily
as a leading "-".
I'm a tad confused.
Kind regards,
Bruce.
More information about the gmp-discuss
mailing list