[Programación] Re: [Programación] Enteros grandes

Nicolás Aimetti programacion@lugro.org.ar
Sat, 19 Nov 2005 17:44:42 -0300


Hola...

Te olvidaste de inicializar el entero res, acá te mando el código 
corregido...
Toda variable de tipo mpz_t debe ser antes incializada 
(http://www.swox.com/gmp/manual/Initializing-Integers.html#Initializing%20Integer)


int main(){
    mpz_t entero1;
    mpz_t entero2;
    mpz_t res;

    mpz_init_set_str(entero1,"12",10);
    mpz_init_set_str(entero2,"12",10);
    mpz_init(res);

    mpz_add(res,entero1,entero2);

    gmp_printf("%Zd\n",res);

    mpz_clear(entero1);
    mpz_clear(entero2);
    mpz_clear(res);
    return 0;
}

Saludos,
             Nicolás.

Emiliano Nuñez wrote:

> Gracias , la verdad que la libreria cubre mis espectativas,, a no ser 
> por el siguiente error, por ejemplo en este sencillo programa::
>
> #include<gmp.h>
> #include<assert.h>
> int main(){
>  mpz_t entero1;
>  mpz_t entero2;
>  mpz_t res;
>  int err;
>  mpz_init_set_str(entero1,"12",10);
>  mpz_init_set_str(entero2,"12",10);
>  mpz_add(res,entero1,entero2);
>  mpz_clear(entero1);
>  mpz_clear(entero2);
>  mpz_clear(res);
>  return 0;
> }
>
> salida : Segmentation fault
>
>
> alguien podra ayudarme???
> salu2.!
>
>
>> From: Nicolás Aimetti <naimetti@yahoo.com.ar>
>> Reply-To: programacion@lugro.org.ar
>> To: programacion@lugro.org.ar
>> Subject: [Programación] Re: [Programación] Re: [Programación] Enteros 
>> grandes (ejemplo)
>> Date: Fri, 18 Nov 2005 14:09:23 +0000
>> MIME-Version: 1.0
>> Received: from lugro.org.ar ([200.3.124.36]) by MC6-F20.hotmail.com 
>> with Microsoft SMTPSVC(6.0.3790.211); Fri, 18 Nov 2005 09:17:29 -0800
>> Received: from lugro.org.ar (localhost [127.0.0.1])by lugro.org.ar 
>> (8.12.3/8.12.3/Debian-7.1) with ESMTP id jAIHH6iI022621;Fri, 18 Nov 
>> 2005 14:17:07 -0300
>> Received: from ns1.via2.com (e-ducativa.iplannetworks.net 
>> [200.69.216.105] (may be forged))by lugro.org.ar 
>> (8.12.3/8.12.3/Debian-7.1) with SMTP id jAIHGYiI022611for 
>> <programacion@lugro.org.ar>; Fri, 18 Nov 2005 14:16:34 -0300
>> Received: (qmail 23713 invoked from network); 18 Nov 2005 17:07:46 -0000
>> Received: from unknown (HELO ?90.0.0.14?) (200.80.179.244)  by 
>> e-ducativa.iplannetworks.net with SMTP; 18 Nov 2005 17:07:46 -0000
>> X-Message-Info: EoYTbT2lH2O3kHxBV5n4FuUtqEBGOZjhcs7QjUP4ApQ=
>> User-Agent: Mozilla Thunderbird 1.0.6 (X11/20051011)
>> X-Accept-Language: en-us, en
>> References: <BAY21-F19435649F33162FE106461D65E0@phx.gbl> 
>> <437DD911.3040300@yahoo.com.ar>
>> Errors-To: programacion-admin@lugro.org.ar
>> X-BeenThere: programacion@lugro.org.ar
>> X-Mailman-Version: 2.0.11
>> Precedence: bulk
>> List-Help: <mailto:programacion-request@lugro.org.ar?subject=help>
>> List-Post: <mailto:programacion@lugro.org.ar>
>> List-Subscribe: 
>> <http://www.lugro.org.ar/mailman/listinfo/programacion>,<mailto:programacion-request@lugro.org.ar?subject=subscribe> 
>>
>> List-Id: <programacion.lugro.org.ar>
>> List-Unsubscribe: 
>> <http://www.lugro.org.ar/mailman/listinfo/programacion>,<mailto:programacion-request@lugro.org.ar?subject=unsubscribe> 
>>
>> List-Archive: <http://www.lugro.org.ar/pipermail/programacion/>
>> Return-Path: programacion-admin@lugro.org.ar
>> X-OriginalArrivalTime: 18 Nov 2005 17:17:31.0197 (UTC) 
>> FILETIME=[F55716D0:01C5EC63]
>>
>>
>> >> A.assign("123456789123456789123456789"); en este caso siendo A el
>> >> numero_grande le asigna el valor entero del numero que contiene esa
>> >> cadena.. no se si alguien podria echarme una mano..
>>
>> Un ejemplo:
>>
>> /* para compilar:  gcc foo.c -lgmp */
>>
>> #include <stdio.h>
>> #include <gmp.h>
>> #include <assert.h>
>>
>>
>> int main(int argc, char *argv[]){
>>     mpz_t entero;
>>     int err;
>>
>>     mpz_init_set_str(entero,"123456789123456789123456789",10);
>>     gmp_printf("numero: %Zd",entero);
>>     mpz_add_ui(entero,entero,10);
>>     gmp_printf(" + 10 = %Zd\n",entero);
>>
>>     mpz_clear (entero);
>>     return 0;
>> }
>>
>>
>> Saludos,
>>         Nicolás.
>>
>>
>> Nicolás Aimetti wrote:
>>
>>> Proba está: http://www.swox.com/gmp/
>>>
>>> Es bastante típica, es parte del proyecto GNU y la usan un motnón de 
>>> aplicaciones... además es muy buena.
>>>
>>> Multiple Precision Arithmetic Library, the fastest bignum library on 
>>> the planet!
>>>
>>> GMP is a free library for arbitrary precision arithmetic, operating 
>>> on signed integers, rational numbers, and floating point numbers. 
>>> There is no practical limit to the precision except the ones implied 
>>> by the available memory in the machine GMP runs on. GMP has a rich 
>>> set of functions, and the functions have a regular interface.
>>>
>>>
>>> Saludos,
>>>         Nicolás.
>>>
>>>
>>> Emiliano Nuñez wrote:
>>>
>>>> Hola , estoy buscando una libreria que me permita trabajar con 
>>>> numeros grandes en c , numeros enteros positivos de longitud 
>>>> arbitraria,, la libreria me tendria que permitir transformar un 
>>>> cadena a entero, por ejemplo:
>>>>
>> _______________________________________________
>> Programacion mailing list
>> Programacion@lugro.org.ar
>> http://www.lugro.org.ar/mailman/listinfo/programacion
>
>
> _________________________________________________________________
> Charla con tus amigos en línea mediante MSN Messenger: 
> http://messenger.latam.msn.com/
>
> _______________________________________________
> Programacion mailing list
> Programacion@lugro.org.ar
> http://www.lugro.org.ar/mailman/listinfo/programacion
>