Problems with (low-level functions) mpn_.

Décio Luiz Gazzoni Filho decio at decpp.net
Tue Oct 5 06:23:14 CEST 2004


The problem with your code is that you are passing variables of type mpz_t as 
arguments to mpn_add_n. mpz_t is just an opaque struct, whereas mpn functions 
expect a pointer to the data itself. This pointer is a member variable of 
said opaque struct. According to gmp.h, the member variable in question is 
_mp_d. I believe if you were to replace numero_0x by numero_0x._mp_d, and 
provided your input data is coherent, the program should work. Please note 
that I have little experience with mpn functions, apart from a few lines of 
code I wrote six months ago.

BTW, are you really sure you need to use these functions? This code I wrote 
required the use of mpn because, with mpz, a step of the algorithm I was 
implementing at the time, which should run in time O(1), would take time 
O(n). Unless you're facing a similar problem, there's no point in using mpn.

Décio

PS: se o inglês estiver difícil de acompanhar, entre em contato comigo 
diretamente (fora da lista).

On Tuesday 05 October 2004 00:23, Moises Deangelo wrote:
> Hey people.
>
> I am new in the forum, I program in C the little time, and the less time
> still use GMP.
>
> I have been trying use GMP low-level (mpn_), but I do not manage to do
> run. I unfortunately do not know where I am being mistaken, I am reading
> the documentation at every moment, but to did not yet get have success.
>
> besides programing the little time, I have a larger difficulty, the
> communication. The English is not my native language and that times
> muddles me too much.
>
> Please, evaluate the code that I send, if someone it can correct him for
> me, or to indicate me some site with material on the subject I am
> thankful.
>
> /*****/
>
> #include <stdio.h>
> #include <stdlib.h>
> #include <gmp.h>
>
> int main ( void )
> {
>     mpz_t   numero_00, numero_01, numero_03;
>     unsigned int    ui_01;
>     char    peg_rn[20];
>
>     puts("\n n0: "); gets(peg_rn);
>     mpz_init_set_str(numero_00, peg_rn, 0);
>
>     puts("\n n1: "); gets(peg_rn);
>     mpz_init_set_str(numero_01, peg_rn, 0);
>
>     puts("\n ui n: "); scanf("%d",&ui_01);
>
>     mpz_init(numero_03);
>
>     mpn_add_n(numero_03, numero_00, numero_01, ui_01);
>
>     printf("\n ui n: %d",ui_01);
>     gmp_printf("\n 00: %Zd",numero_00);
>     gmp_printf("\n 01: %Zd",numero_01);
>     gmp_printf("\n 03: %Zd",numero_03);
> }
>
> /*****/
>
> I am sending that fragment, but already I tried several options. Already
> I changed that code without many times geting results. I just do not am
> going to post all the forms that I tried to do that code work because
> the e-mail would be very large, being that unnecessary.
>
> what I wish, it is to comprehend mpn operation, that code that I created
> is only a test to comprehend that. :-(
>
> Please, comprehend,  is not laziness,  I do not wish anything chewed,
> have me diligent, but it has been being hard.
>
> I work cygwin. C and GMP 4.1.2.
>
> Moises Deangelo
> lewris at ig.com.br
> ICQ:89529510
> Brazil
>
>
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss at swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 190 bytes
Desc: not available
Url : /list-archives/gmp-discuss/attachments/20041005/30da76e5/attachment.bin


More information about the gmp-discuss mailing list