## Name:

libraryconstant
binds an external mathematical constant to a variable in Sollya

## Library names:

sollya_obj_t sollya_lib_libraryconstant(char *, void (*)(mpfr_t, mp_prec_t))
sollya_obj_t sollya_lib_build_function_libraryconstant(char *,
void (*)(mpfr_t,
mp_prec_t))
## Description:

- The command libraryconstant lets you extend the set of mathematical
constants known to Sollya.
By default, the only mathematical constant known by Sollya is pi.
For particular applications, one may want to
manipulate other constants, such as Euler's gamma constant, for instance.
- libraryconstant makes it possible to let Sollya know about new constants.
In order to let it know, you have to provide an implementation of the
constant you are interested in. This implementation is a C file containing
a function of the form:
void my_ident(mpfr_t result, mp_prec_t prec)
The semantic of this function is the following: it is an implementation of
the constant in arbitrary precision.
my_ident(result, prec) shall set the
precision of the variable result to a suitable precision (the variable is
assumed to be already initialized) and store in result an approximate value
of the constant with a relative error not greater than 2^(1-prec).
More precisely, if c is the exact value of the constant, the value stored
in result should satisfy |result-c| <= 2^(1-prec)*|c|.
- You can include sollya.h in your implementation and use library
functionnalities of Sollya for your implementation. However, this requires to
have compiled Sollya with -fPIC in order to make the Sollya executable
code position independent and to use a system on with programs, using dlopen
to open dynamic routines can dynamically open themselves.
- To bind your constant into Sollya, you must use the same identifier as the
function name used in your implementation file (my_ident in the previous
example). Once the function code has been bound to an identifier, you can use
a simple assignment to assign the bound identifier to yet another identifier.
This way, you may use convenient names inside Sollya even if your
implementation environment requires you to use a less convenient name.
- Once your constant is bound, it is considered by Sollya as an infinitely
accurate constant (i.e. a 0-ary function, exactly like pi).

## Example 1:

> bashexecute("gcc -fPIC -Wall -c libraryconstantexample.c -I$HOME/.local/include");

> bashexecute("gcc -shared -o libraryconstantexample libraryconstantexample.o -lgmp -lmpfr");

> euler_gamma = libraryconstant("./libraryconstantexample");

> prec = 20!;

> euler_gamma;

0.577215

> prec = 100!;

> euler_gamma;

0.577215664901532860606512090082

> midpointmode = on;

Midpoint mode has been activated.

> [euler_gamma];

0.57721566490153286060651209008~2/4~

Go back to the list of commands