Newer Older
Paritwine allows to easily switch between number types from the GNU
Andreas Enge's avatar
Andreas Enge committed
2 3 4 5 6 7 8
multiprecision ecosystem (mpz, mpq, mpfr, mpc) and corresponding types in
libpari, as well as to use functions from the GNU libraries in GP.


The exported functions are given in paritwine.h. For each GNU
Andreas Enge's avatar
Andreas Enge committed
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
multiprecision type X from mpz, mpq, mpfr and mpc, there are functions
The first one takes an argument x of type X and g of type GEN, and assigns
the value of g to x if the types are compatible. The second one takes as
argument x of type X and returns a GEN with the same value, allocated on the
Pari stack.

The functions pari_mpfr_init2, pari_mpc_init2 and pari_mpc_init3 work
exactly as their counterparts without the pari prefix, except that they
allocate the mantissae on the Pari stack instead of using the GMP memory
allocation functions. They should not be freed with calls to mpfr_clear or
mpc_clear, but with the usual Pari stack handling ("avma").
pari_mpfr_init_set_GEN and pari_mpc_init_set_GEN combine such an
initialisation with an assignment; as precision, they use the precision of
the source variable if it is of a floating point type, or the default
precision if it is an integer or a rational number. If you are unsure what
is meant by this paragraph, you probably do not wish to use these functions.


If you wish to use functions relying on GMP, GNU MPFR, GNU MPC or CMH in a
34 35
GP session, you need to write a wrapper function in paritwine-user.c and
declare it in paritwine-user.h. The function should take GEN arguments,
Andreas Enge's avatar
Andreas Enge committed
36 37 38 39
transform them to mpz, mpq, mpfr or mpc, compute with them in the desired
way, and transform the result back into a GEN. By calling
this function will be automatically included into the library
40 The functions must then be made available inside your GP
Andreas Enge's avatar
Andreas Enge committed
41 42
session using the "install" command.

As examples, paritwine-user.c implements correctly rounded multiplications
Andreas Enge's avatar
Andreas Enge committed
44 45 46 47
of real and complex numbers using MPFR and MPC, as well as the erf and zeta
functions from MPFR. The file shows how to install and use these
functions in a GP script.