- 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).
- The dynamic object file whose name is given to libraryconstant for binding of an external library constant may also define a destructor function int sollya_external_lib_close(void). If Sollya finds such a destructor function in the dynamic object file, it will call that function when closing the dynamic object file again. This happens when Sollya is terminated or when the current Sollya session is restarted using restart. The purpose of the destructor function is to allow the dynamically bound code to free any memory that it might have allocated before Sollya is terminated or restarted. The dynamic object file is not necessarily needed to define a destructor function. This ensure backward compatibility with older Sollya external library function object files. When defined, the destructor function is supposed to return an integer value indicating if an error has happened. Upon success, the destructor functions is to return a zero value, upon error a non-zero value.

> 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~