# Introduction

Pari-Gnump
allows to easily switch between number types from the
GNU multiprecision ecosystem
(`mpz`

, `mpq`

,
`mpfr`

, `mpc`

) and corresponding types in
libpari, as well as to use functions from the
GNU libraries in GP.

## Installation

Adapt the location and version numbers of
Pari/GP, GNU MP (GMP),
GNU MPFR and GNU MPC in the first lines
of `Makefile`

.

If you wish to use functions relying on GMP,
GNU MPFR or GNU MPC in
your GP session,
you need to add them to
`pari-gnump-user.h`

and `pari-gnump-user.c`

.

Execute

make

This creates the library `libpari-gnump.so`

.
There is no need to install this
library, it may simply be copied to the location of your
Pari/GP project.

To test if everything went well, execute

make check

## Number transformations

The exported functions are given in `pari-gnump.h`

.
For each GNU multiprecision type `X`

from
`mpz`

, `mpq`

, `mpfr`

and `mpc`

,
there are functions
X_set_GEN
X_get_GEN
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.

## User functions in GP

If you wish to use functions relying on
GMP, GNU MPFR or
GNU MPC in a
GP session, you need to write a wrapper function in
`pari-gnump-user.c`

and
declare it in `pari-gnump-user.h`

.
The function should take `GEN`

arguments,
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
make
this function will be automatically included into the library
libpari-gnump.so. The functions must then be made available inside your
GP session using the `install`

command.

As examples, `pari-gnump-user.c`

implements correctly rounded
multiplications of real and complex numbers using MPFR and
MPC, as well as the erf and zeta
functions from MPFR.
The file `example.gp`

shows how to install and use these
functions in a GP script.