Test Foro de elhacker.net SMF 2.1

Programación => Programación C/C++ => Mensaje iniciado por: m@o_614 en 18 Marzo 2014, 15:41 PM

Título: mpz_set_str()
Publicado por: m@o_614 en 18 Marzo 2014, 15:41 PM
alguien que conozca alguna funcion de la libreria gmp que me permita ingresar enteros??, tengo la función mpz_set_str(num,text.c_str(),10); pero en esta el segundo miembro tiene que ser un string, y eso es lo que no quiero necesito una función que me ingrese un entero sin el uso de cadenas

gracias
Título: Re: mpz_set_str()
Publicado por: eferion en 18 Marzo 2014, 15:50 PM
¿Es esto lo que buscabas?


Assignment Functions


These functions assign new values to already initialized integers (see section Initialization and Assignment Functions).

Function: void mpz_set (mpz_t rop, mpz_t op)
Function: void mpz_set_ui (mpz_t rop, unsigned long int op)
Function: void mpz_set_si (mpz_t rop, signed long int op)
Function: void mpz_set_d (mpz_t rop, double op)
Function: void mpz_set_q (mpz_t rop, mpq_t op)
Function: void mpz_set_f (mpz_t rop, mpf_t op)
   Set the value of rop from op.

Function: int mpz_set_str (mpz_t rop, char *str, int base)
   Set the value of rop from str, a '\0'-terminated C string in base base. White space is allowed in the string, and is simply ignored. The base may vary from 2 to 36. If base is 0, the actual base is determined from the leading characters: if the first two characters are `0x' or `0X', hexadecimal is assumed, otherwise if the first character is `0', octal is assumed, otherwise decimal is assumed.
   This function returns 0 if the entire string up to the '\0' is a valid number in base base. Otherwise it returns -1.


Título: Re: mpz_set_str()
Publicado por: Gh057 en 18 Marzo 2014, 16:00 PM
hola m@o_614, las mayoría de las funciones definidas en esa biblioteca aceptan tanto números, como cadenas; es por un tema de eficiencia. (puedes pasar el entero a cadena y operar de una manera más rápida)

-> http://es.wikipedia.org/wiki/GNU_Multiple_Precision_Arithmetic_Library

-> https://gmplib.org/manual/

adentro tienes un detalle extenso de toda la bibioteca, sin embargo te dejo un enlace directo a el manejo con enteros.

-> https://gmplib.org/manual/Integer-Functions.html#Integer-Functions

(igual mira el tema del manejo de candenas...)

espero haberte ayudado, saludos.
Título: Re: mpz_set_str()
Publicado por: m@o_614 en 19 Marzo 2014, 01:03 AM
Muchas gracias ahora ya comprendi mejor para que sirve cada función