How to use GMP.
Hashida
jhashida@fls.fujitsu.com
Tue, 06 May 2003 14:33:57 +0900
Hi Tomonori Kouya.
I thank you for a reply.
Certainly the following list works correctly.
But I have a point which I can't understand.
When I convert mpz_t into MP_INT,
the following list can't be compiled.
The following message emerges.
incompatible type for argument 1 of '__gmp_init_set_str'
incompatible type for argument 1 of '__gmp_init'
incompatible type for argument 1 of '__gmpmul_ui'
incompatible type for argument 2 of '__gmpmul_ui'
In "gmp.h" file,
"typedef __mpz_struct MP_INT;"
and
"typedef __mpz_struct mpz_t[1];"
are defined.
"__mpz_struct" is as follows.
typedef struct
{
int _mp_alloc;
int _mp_size;
mp_limb_t *_mp_d;
} __mpz_struct;
Is "MP_INT" equal to "mpz_t" ?
"MP_INT" is used in"FreeS/WAN" which is ipsec stack on Linux.
Because I want to understand "MP_INT" structure, tried with my first
program.
Regards.
Hashida
juneco@quartz.ocn.ne.jp wrote:
> Tomonori Kouya here.
>
> Your program is not standard, I think. If you get correct results only,
> how about the following list ?
>
> #include <stdio.h>
> #include <gmp.h>
> #include <stdarg.h>
> //#include <obstack.h>
>
> main()
> {
> mpz_t bbbbb, aaaaa;
>
> mpz_init_set_str(bbbbb,"2147483647", 10);
>
> mpz_init(aaaaa);
> mpz_mul_ui(aaaaa, bbbbb, 3);
>
> gmp_printf("bbbbb=%Zd\n",bbbbb);
> gmp_printf("aaaaa=%Zd\n",aaaaa);
>
> mpz_clear(bbbbb);
> mpz_clear(aaaaa);
> }
>
> Results on Pentium 4 PC with Windows XP and GMP 4.1.2:
>
> $ ./a
> bbbbb=2147483647
> aaaaa=6442450941
>
> Hashida <jhashida@fls.fujitsu.com>さん:
> > Hi
> >
> > I am a beginner for GMP and not good at C.
> > I can't understand how to use GMP very well.
> > For example, in arithmetic of 231*3
> > I wrote the following C program.
> >
> > #include <stdio.h>
> > #include <gmp.h>
> > #include <stdarg.h>
> > #include <obstack.h>
> >
> > main()
> > {
> > MP_INT *bbbbb=(MP_INT *)malloc(50);
> > MP_INT aaaaa;
> >
> > bbbbb->_mp_d=(mp_limb_t *)malloc(10);
> >
> > mpz_init_set_ui(bbbbb,2147483647);
> > printf("bbbbb->_mp_alloc=%d\n",bbbbb->_mp_alloc);
> > printf("bbbbb->_mp_size=%d\n",bbbbb->_mp_size);
> > printf("*(bbbbb->_mp_d)=%d\n",*(bbbbb->_mp_d));
> > mpz_init(&aaaaa);
> > mpz_mul_ui(&aaaaa, bbbbb, 3);
> > printf("aaaaa._mp_alloc=%d\n",aaaaa._mp_alloc);
> > printf("aaaaa._mp_size=%d\n",aaaaa._mp_size);
> > printf("*(aaaaa._mp_d)=%d\n",*(aaaaa._mp_d));
> >
> > }
> >
> > The result of the execution of this program is as follows.
> >
> > bbbbb->_mp_alloc=1
> > bbbbb->_mp_size=1
> > *(bbbbb->_mp_d)=2147483647
> > aaaaa._mp_alloc=2
> > aaaaa._mp_size=2
> > *(aaaaa._mp_d)=2147483645
> >
> > 231*3 is 6442450944 in decimal system.
> >
> > Please teach me how to recognize 6442450944 from the above result.
> > Simply the way of the usage of "printf" may be bad, but I don't know.
> >
> > Thanks.
> >
> > Hashida
> >
> _______________________________________________
> gmp-discuss mailing list
> gmp-discuss@swox.com
> https://gmplib.org/mailman/listinfo/gmp-discuss