[R] gmp

Josef Eschgfaeller esg at felix.unife.it
Wed Nov 19 10:41:34 CET 2003


I'm trying to write some GMP functions but am not sure about
how and where to use pointers.
----------------------------------------------------------------------
// alfa.c
# include <R.h>
# include <gmp.h>

void Createinteger (char *A, mpz_t *N)
{mpz_init(*N); mpz_set_str(*N,A,10);}

void Stringofinteger (mpz_t *X, char ** A)
{*A=mpz_get_str(0,10,*X);}

void Square (mpz_t *X, mpz_t *Y)
{mpz_mul(*X,*X,*Y);}
----------------------------------------------------------------------
R-source:

Square = function (x) {u=0; .C('Createinteger',x,u);
  .C('Square',u,u); # (*)
  .C('Stringofinteger',u,a); a}

u=Square('105')
----------------------------------------------------------------------
As output I obtain always 1 2 3, also if omitting (*).
Someone who knows better? Is there already some package for GMP or
similar multiprecision libraries?

Josef Eschgfäller




More information about the R-help mailing list