This is the official documentation for libinum, version 1.0.
libinum is a C library that implements several algorithms, intended for applications in numerical and symbolic computations.
libinum defines functions to perform the following tasks:
As a general rule, the functions and structures can be used with several different data types. For instance, the root finding and integration functions can manipulate double precision, extended precision, or multi-precision floating point numbers. See Data types for details.
One of the guiding principles of libinum is that it should should not push a specific data type on users. If, hypothetically, the computation being carried out requires the precision of the floating point numbers to be large, then multi-precision floating point numbers might be preferable to double precision numbers. If, instead, computation time is more important than precision, then extended precision floats may be preferred. The structures and functions defined in libinum, therefore, support various data types.
We will now briefly discuss the data types that may be used to represent numbers.
The standard integer types of the C language are char
, short int
, int
, long int
and long long int
, as well as their unsigned
counterparts. The number of bits, and, in consequence, the available range of integers, of each of these types, is platform-dependent. In cases where this could be problematic, fixed-precision integers can be used: with 8 bits: int8_t
, 16: int16_t
, 32: int32_t
and 64: int64_t
.
libinum provides a function, print_datatype_info()
, that prints the equivalence table between char
, short int
, int
, long int
and long long int
and int8_t
, int16_t
, int32_t
and int64_t
for the implementation of the C library used to compile libinum.
In cases where the required number of bits of integers exceeds 64, one can use multi-precision integers, which can be as large as will fit in memory. However, computation times can greatly increase when using multi-precision integers. The implementation used in libinum is provided by the GNU GMP library.
Let us first start with a description of floating point numbers. A real number \(x\) is approximated, with a precision of \(m\) bits, as a collection of three numbers: the sign \(s\in\{-1,1\}\); mantissa, whose binary expansion is denoted by \(a_1\cdots a_m\); and exponent \(e\in\mathbb Z\). The approximate value of the number \(x\) is obtained from its sign, mantissa and exponent by $$ x=s\times a_1.a_2\cdots a_m\times2^e. $$ The precision of a floating point number is the number of bits allocated to its sign and mantissa (since \(a_1\) is necessarily equal to \(1\), it is not stored, so the precision of \(x\) is \(m\) instead of \(m+1\)).
In libinum, floating point number may either be double, extended or multi-precision numbers.
Double precision floats are represented using the double
type.
The precision and maximal and minimal values of the exponent of double
floats depends on the compiler. Their values can be printed using the libinum function print_datatype_info()
.
For example, using version 5.3.0 of the GNU GCC compiler on the x86-64 architecture, the precision is of 53 bits (i.e. 15 decimal digits), and the maximal and minimal values of the exponent are 1024 and -1021.
Extended precision floats are represented using the long double
type. They require more memory than double precision floats, and, as a consequence, slightly more computation time.
The precision and maximal and minimal values of the exponent of long double
floats depends on the compiler. Their values can be printed using the libinum function print_datatype_info()
.
For example, using version 5.3.0 of the GNU GCC compiler on the x86-64 architecture, the precision is of 64 bits (i.e. 18 decimal digits), and the maximal and minimal values of the exponent are 16384 and -16381.
A multi-precision floating point number is a floating point number whose precision can be set to an arbitrary value (until the number fills up the entire memory of the computer). In libinum, multi-precision floats are implemented using the GNU MPFR library, and will be called MPFR floats.
The precision of MPFR floats can be set using the function mpfr_set_default_prec
(see the MPFR library documentation for details). The default value of the precision is 53 bits (as of version 3.1.4 of the MPFR library).
In addition, the maximal value (in absolute value) of the exponent can be controlled by setting emax using the function mpfr_set_emax
(see the MPFR library documentation for details).
Depending on the MPFR implementation, the precision and emax can either be an int
or a long int
, so its maximal and minimal values are platform dependent. The libinum function print_datatype_info()
prints which it is.
What follows is a detailed description of the functions that implement the algorithms supported by libinum.
libinum can compute the root of smooth real functions using the Newton-Raphson algorithm. The algorithm converges quickly, provided an adequate approximation of the root in provided, and that the root is not located at a minimum of the function.
Given a function \(f\) and a real number \(x_0\), the algorithm produces a sequence \((x_n)\) which, provided the algorithm converges, tends to a root of \(f\). The sequence is defined as $$ x_{n+1}=x_n-\frac{f(x_{n})}{f'(x_{n})} $$ where \(f'\) denotes the derivative of \(f\). The following estimate holds: $$ |x_{n+1}-x_n|\leqslant \frac12|x_n-x_{n-1}|^2\sup_{\xi\in[x_{n+1},x_n]}\frac{f''(\xi)}{f'(\xi)} $$ so that, provided \(f\) is smooth and its derivative does not vanish in the intervals \([x_{n+1},x_n]\), the algorithm converges quadratically.
This algorithm has been implemented using double, extended and multi-precision floats.
out
: pointer to the number to which the result will be written. If the number requires initialization (e.g. if it is an mpfr_t
), then it must be initialized.
func
: pointer to the function that computes \(f(x)\). It must be in the format specified in functions.
deriv_func
: pointer to the function that computes the derivative of \(f\). It must be in the format specified in functions.
init
: the value of \(x_0\).
tolerance
: the algorithm halts when \(|x_{n+1}-x_n|\leqslant\)tolerance
. tolerance
thus provides control over the error of the algorithm.
maxiter
: maximum number of iterations. The algorithm gives up if this number is reached and throws a LIBINUM_ERROR_MAXITER
exception.
extra_args
: pointer to the extra arguments to be passed to the functions *func
and *deriv_func
when they are evaluated.
0
on success, and
LIBINUM_ERROR_MAXITER
if the maximal number of iterations was reached.LIBINUM_ERROR_NAN
if any of the evaluations of *func
or *deriv_func
returned nan
or infinity
, or if any of the evaluations of *deriv_func
returned 0
.root_newton_*
except that the value of \(x_0\) is passed to the function in the argument out
.
libinum can compute definite integrals of smooth real functions using Gauss-Legendre quadratures.
The main idea of Gauss-Legendre quadratures is to find a set of abcissa \(\{t_1,\cdots,t_N\}\in[-1,1]^N\) and weights \(\{w_1,\cdots,w_N\}\in\mathbb R^N\) such that, if \(f\) were a polynomial of degree \(\leqslant2N-1\), then the integral would be equal to a discrete sum: $$ \int_{a}^bdx\ f(x)=\sum_{i=1}^Nw_if\left(\frac{a+b}2+t_i\frac{b-a}2\right). $$ In the general case, if \(f\) is \(\mathcal C^{2N}\), then $$ \left|\int_{a}^bdx\ f(x)-\sum_{i=1}^Nw_if\left(\frac{a+b}2+t_i\frac{b-a}2\right)\right| \leqslant \frac{N!^4}{(2N+1)(2N)!^3}\sup_{x\in[a,b]}\frac{d^{2N}f(x)}{dx^{2N}}. $$ The number \(N\) is called the order of the integration.
As it turns out, the abcissa are the roots of the \(N\)-th Legendre polynomial \(L_N\), defined by the recursive equation $$ (N+1)L_{N+1}(x)=(2N+1)xL_N(x)-NL_{N-1}(x),\quad L_0(x)=1,\quad L_1(x)=x $$ and the weights are $$ w_i=\frac2{(1-x_i^2)L_N'(t_i)}. $$
This algorithm has been implemented using double, extended and multi-precision floats
out
: pointer to the number to which the result will be written. If the number requires initialization (e.g. if it is an mpfr_t
), then it must be initialized.
func
: pointer to the function that computes the integrand \(f(x)\). It must be in the format specified in functions.
lower
: lower bound of the integration.
upper
: upper bound of the integration.
abcissa
: the abcissa used to compute the integral using Gauss quadratures. For Gauss-Legendre integration, they can be computed by the function gauss_legendre_weights
.
weights
: the weights used to compute the integral using Gauss quadratures. For Gauss-Legendre integration, they can be computed by the function gauss_legendre_weights
.
extra_args
: pointer to the extra arguments to be passed to the function *func
when it is evaluated (see functions).
0
on success, and
LIBINUM_ERROR_NAN
if any of the evaluations of *func
returned nan
or infinity
.LIBINUM_ERROR_SIZE_MISMATCH
if the lengths of the vectors abcissa
and weights
are different.integrate_gauss_*
, in which function calls are performed in parallel.integrate_gauss_*
, except for
threads
: number of threads to use for the computation.
thread_ids
: pointer to an array in which the id of each thread is written to. The array must not be initialized. This array can then be used by each thread to identify themselves.
integrate_gauss_*
.
integrate_gauss_*
, except that, if temporary floats are needed during the computation, they are saved to an array so that they can be re-used later on. This is useful to perform repeated integrations, in which it would be costly to re-allocate memory for temporary floats. When using this function, temporary floats are allocated as needed, but they are not discarded.integrate_gauss_*
, except for
tmps
: pointer to an array that is used to store temporary floats. The array must be initialized beforehand. When temporary floats are needed, the array is checked for available floats. If enough of them are already present in the array, then the routine uses them, if not, it enlarges the array and allocates as many extra floats as is needed. The floats in the array can then be re-used for other purposes.
integrate_gauss_*
.
integrate_gauss_smarttmp_*
, in which function calls are performed in parallel.integrate_gauss_smarttmp_*
, except for
threads
: number of threads to use for the computation.
thread_ids
: pointer to an array in which the id of each thread is written to. The array must not be initialized. This array can then be used by each thread to identify themselves.
integrate_gauss_*
.
order
: the order \(N\) of the integration.
tolerance
: tolerance for the Newton algorithm used to compute the roots of the Legendre polynomial (see root_newton
).
maxiter
: the maximal number of steps to compute before giving up.
abcissa
: pointer to the array in which to write the abcissa. It must not be initialized.
weights
: pointer to the array in which to write the weights. It must not be initialized.
0
on success, and
LIBINUM_ERROR_MAXITER
if, when computing the roots of the Legendre polynomial using a Newton iteration, the maximal number of iterations was reached.What follows is a detailed description of the C types defined in libinum.
array
Array that can be dynamically resized.
array_${TYPENAME}
:
{ ${TYPE}* values, unsigned int length, unsigned int memory }
");
}
?>
values
: the array in which the objects are storedlength
: the number of elements in the arraymemory
: the number of elements allocated to the arrayarray_*
's must be initialized before they are used, and freed when they are no longer needed. khen the array is freed, the objects it contains are freed as well.
int array_${TYPENAME}_init(array_${TYPENAME}* array, unsigned int memory)
");
}
?>
array
, and allocate memory
elements.
int array_${TYPENAME}_free(array_${TYPENAME} array)
array
.
int array_${TYPENAME}_free_vects(array_${TYPENAME} array)
array.values
, but do not free the elements of the array.
int array_${TYPENAME}_resize(array_${TYPENAME}* array, unsigned int newsize)
");
}
?>
array
to another with memory newsize
.
int array_${TYPENAME}_append(${TYPE} value, array_${TYPENAME}* array)
");
}
?>
value
to the end of the array pointed to by array
. Resize the array if needed.
int array_${TYPENAME}_append_noinit(${TYPE} value, array_${TYPENAME}* array)
");
}
?>
value
to the end of the array pointed to by array
. Do not initialize the new value, instead, copy value
to the end of *array
. value
must not be freed, since it will be freed when *array
is. Resize the array if needed.
int array_${TYPENAME}_concat(array_${TYPENAME} input, array_${TYPENAME}* output)
");
}
?>
input
to the end of the array pointed to by output
. Resize the array if needed.
int array_${TYPENAME}_cpy(array_${TYPENAME} input, array_${TYPENAME}* output)
");
}
?>
input
to the array pointed to by output
. Initializes *output
.
int array_${TYPENAME}_cpy_noinit(array_${TYPENAME} input, array_${TYPENAME}* output)
");
}
?>
input
to the array pointed to by output
. Does not initialize *output
, so *output
must be initialized ahead of time, and its memory must be larger or equal to the length of input
. Returns LIBINUM_ERROR_SIZE_MISMATCH
if the memory of *output
is smaller than the length of input
.
int array_${TYPENAME}_subarray(array_${TYPENAME} array, unsigned int begin, unsigned int end, array_${TYPENAME}* subarray)
");
}
?>
array
whose indices are larger or equal to begin
and smaller or equal to end
. Returns LIBINUM_ERROR_ILLEGAL_MEMORY_ACCESS
if the subarray does not exist.
int array_${TYPENAME}_print(array_${TYPENAME} array)
");
}
?>
array
.
int, unsigned int, double, long double, mpfr, char
array_char
polynomial_*
.int array_${TYPENAME}_append_unique(${TYPE} value, array_${TYPENAME}* array)
");
}
?>
value
is not already present in the array pointed to by array
, then append it. Resize the array if needed.
int array_${TYPENAME}_concat_unique(array_${TYPENAME} input, array_${TYPENAME}* output)
");
}
?>
input
that are not already present in the array pointed to by output
. Resize the array if needed.
int array_${TYPENAME}_find(${TYPE} val, array_${TYPENAME} array)
");
}
?>
val
in array
. Returns the index of val
in array
if it is present, and -1
if it is not.
int array_${TYPENAME}_sort(array_${TYPENAME} array)
");
}
?>
array
from smallest to largest (for numerical values, the ordering relation is the usual one, for characters and strings, the lexicographical ordering is used). The sorting is performed in place. The quicksort algorithm is used.
int array_${TYPENAME}_sort_sub(array_${TYPENAME} array, unsigned int begin, unsigned int end)
");
}
?>
array
consisting of the elements whose index is larger or equal than begin
and smaller or equal than end
. The sorting is performed in place. The quicksort algorithm is used.
int array_${TYPENAME}_cmp(array_${TYPENAME} array1, array_${TYPENAME} array2)
");
}
?>
array1
and array2
. Returns 0
if both arrays are equal (that is, if their elements are the same, and in the same order), -1
if array1
is smaller than array2
in lexicographical order, and 1
if array1
is smaller than array2
in lexicographical order.
array_char
array_char
.
int array_char_append_str(char* str, array_char* output)
str
to the end of the array pointed to by output
. Resize the array if needed.
int array_char_to_str(array_char input, char** output)
input
to the string pointed to by output
. Initializes *output
.
char* array_char_to_str(array_char* input)
input
to a string, and return it. Appends '\0'
at the end of *input
. The string thus generated should not be freed, since it is actually a pointer to input->str
, which is freed when *input
is.
int str_to_array_char(char* str, array_char* output)
input
to the array pointed to by output
. Initializes *output
.
int array_char_cmp_str(array_char array_char, char* str)
array_char
and the string str
. Returns 1
if the strings are identical, and 0
if not.
int array_char_snprintf(array_char* output, char* fmt)
fmt
and appends the output to the array pointed to by output
. The format should follow the specifications of the standard C function printf
.
polynomial
A polynomial with real coefficients. A polynomial
is represented as an array of coefficients and an array of exponents. For example \(1+x+2x^2\) is represented as ({1.,1.,2.},{0,1,2})
.
polynomial_${TYPENAME}
:
{ array_${COEFTYPENAME} coefficients, array_${EXPTYPENAME} orders }
");
}
?>
coefficients
: array of coefficientsorders
: array of exponents.polynomial_*
's must be initialized before they are used, and freed when they are no longer needed.
polynomial_${TYPENAME}_init(polynomial_${TYPENAME}* poly, unsigned int memory)
");
}
?>
poly
, and allocate memory
terms.
polynomial_${TYPENAME}_free(polynomial_${TYPENAME} poly)
");
}
?>
poly
.
polynomial_${TYPENAME}_resize(polynomial_${TYPENAME}* poly, unsigned int newsize)
");
}
?>
poly
to another with memory newsize
.
polynomial_${TYPENAME}_add_monomial(${COEFTYPE} val, ${EXPTYPE} order, polynomial_${TYPENAME}* output)
");
}
?>
val
and exponent order
to the polynomial pointed to by output
. Resize the polynomial if needed.
polynomial_${TYPENAME}_add_monomial_dui(double val, unsigned int order, polynomial_${TYPENAME}* output)
");
}
?>
val
(converted from a double
) and exponent order
(converted from an unsigned int
) to the polynomial pointed to by output
. Resize the polynomial if needed.
polynomial_${TYPENAME}_cpy(polynomial_${TYPENAME} input, polynomial_${TYPENAME}* output)
");
}
?>
input
to the polynomial pointed to by output
. Initializes *output
.
polynomial_${TYPENAME}_cpy_noinit(polynomial_${TYPENAME} input, polynomial_${TYPENAME}* output)
");
}
?>
input
to the polynomial pointed to by output
. Does not initialize *output
, so *output
must be initialized ahead of time, and its memory must be larger or equal to the length of input
. Returns LIBINUM_ERROR_SIZE_MISMATCH
if the memory of *output
is smaller than the length of input
.
polynomial_${TYPENAME}_add(polynomial poly1, polynomial_${TYPENAME} poly2, polynomial_${TYPENAME}* output)
");
}
?>
poly1
and poly2
and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomial_${TYPENAME}_add_inplace(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME}* poly2)
");
}
?>
poly1
and *poly2
and write the result to the polynomial pointed to by poly2
.
polynomial_${TYPENAME}_mul_scalar(${COEFTYPE} x, polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)
");
}
?>
x
and poly
and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomial_${TYPENAME}_mul_scalar_inplace(${COEFTYPE} x, polynomial_${TYPENAME}* poly)
");
}
?>
x
and *poly
and write the result to the polynomial pointed to by poly
.
polynomial_${TYPENAME}_mul_monomial(${COEFTYPE} x, ${EXPTYPE} order, polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)
");
}
?>
poly
and the monomial whose coefficient and exponent are x
and order
, and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomial_${TYPENAME}_mul_monomial_inplace(${COEFTYPE} x, ${EXPTYPE} order, polynomial_${TYPENAME}* poly)
");
}
?>
*poly
and the monomial whose coefficient and exponent are x
and order
, and write the result to the polynomial pointed to by poly
.
polynomial_${TYPENAME}_mul(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME} poly2, polynomial_${TYPENAME}* output)
");
}
?>
poly1
and poly2
and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomial_${TYPENAME}_mul_inplace(polynomial_${TYPENAME} poly1, polynomial_${TYPENAME}* poly2)
");
}
?>
poly1
and *poly2
and write the result to the polynomial pointed to by poly2
.
polynomial_${TYPENAME}_derive(polynomial_${TYPENAME} poly, polynomial_${TYPENAME}* output)
");
}
?>
poly
and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomial_${TYPENAME}_derive_inplace(polynomial_${TYPENAME}* poly)
");
}
?>
*poly
and write the result to the polynomial pointed to by poly
.
polynomial_${TYPENAME}_evaluate(${COEFTYPE}* out, ${COEFTYPE} x, polynomial_${TYPENAME} poly)
");
}
?>
poly
at x
, and write the result to out
. out
must be initialized if its type requires it.
polynomial_${TYPENAME}_print(polynomial_${TYPENAME} poly)
");
}
?>
poly
.
polynomial_${TYPENAME}_legendre(unsigned int n, polynomial_${TYPENAME}* output)
");
}
?>
n
-th Legendre polynomial, and write the output to the polynomial pointed to by poly
. Initializes *poly
.
polynomialMV
Multi-variable polynomials. A polynomial
is represented as an array of coefficients and an array of arrays of indices, each of which represents a variable. For example, \(3x_1^2+x_1x_2\) is represented as ({3,1},{{1,1},{1,2}})
.
polynomialMV_${TYPENAME}
:
{ ${COEFTYPE}* coefficients, array_${INDEXTYPENAME} factors, unsigned int length, unsigned int memory }
");
}
?>
coefficients
: array of coefficientsfactors
: array of factors, i.e. arrays of indices of variableslength
: the number of terms in the polynomialmemory
: the number of terms allocated to the polynomialpolynomialMV_*
's must be initialized before they are used, and freed when they are no longer needed. When the polynomial is freed, its coefficients and factors are freed as well.
polynomialMV_${TYPENAME}_init(polynomialMV_${TYPENAME}* poly, unsigned int memory)
");
}
?>
poly
, and allocate memory
terms.
polynomialMV_${TYPENAME}_free(polynomialMV_${TYPENAME} poly)
");
}
?>
poly
.
polynomialMV_${TYPENAME}_resize(polynomialMV_${TYPENAME}* poly, unsigned int newsize)
");
}
?>
poly
to another with memory newsize
.
polynomialMV_${TYPENAME}_cpy(polynomialMV_${TYPENAME} input, polynomialMV_${TYPENAME}* output)
");
}
?>
input
to the polynomial pointed to by output
. Initializes *output
.
polynomialMV_${TYPENAME}_cpy_noinit(polynomialMV_${TYPENAME} input, polynomialMV_${TYPENAME}* output)
");
}
?>
input
to the polynomial pointed to by output
. Does not initialize *output
, so *output
must be initialized ahead of time, and its memory must be larger or equal to the length of input
. Returns LIBINUM_ERROR_SIZE_MISMATCH
if the memory of *output
is smaller than the length of input
.
polynomialMV_${TYPENAME}_append(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)
");
}
?>
coef
and factor factor
to the polynomial pointed to by output
. Resize the polynomial if needed.
polynomialMV_${TYPENAME}_append_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)
");
}
?>
polynomialMV_*_append
except that if the factor is already present in the polynomial pointed to by output
, then add coef
to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
polynomialMV_${TYPENAME}_append_noinit(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)
");
}
?>
polynomialMV_*_append
except that the new factor and coefficient to be appended to the polynomial pointed to by output
are not allocated. Instead, pointers to factor
and coef
are appended. factor
and coef
must therefore not be freed (since they will be freed when output
is). Resize the polynomial if needed.
polynomialMV_${TYPENAME}_append_noinitfactor(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomialMV_${TYPENAME}* output)
");
}
?>
polynomialMV_*_append
except that the new factor to be appended to the polynomial pointed to by output
is not allocated. Instead, a pointer to factor
is appended. factor
must therefore not be freed (since it will be freed when output
is). coef
is, however, copied and must be freed. Resize the polynomial if needed.
polynomialMV_${TYPENAME}_append_noinit_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomial* output)
");
}
?>
polynomialMV_*_append_noinit
except that if the factor is already present in the polynomial pointed to by output
, then add coef
to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
polynomialMV_${TYPENAME}_append_noinit_inplace(array_${INDEXTYPENAME} factor, ${COEFTYPE} coef, polynomial* output)
");
}
?>
polynomialMV_*_append_noinitfactor
except that if the factor is already present in the polynomial pointed to by output
, then add coef
to the coefficient of that factor, instead of appending it to the end of the polynomial. Resize the polynomial if needed.
polynomialMV_${TYPENAME}_add(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME} poly2, polynomialMV_${TYPENAME}* output)
");
}
?>
poly1
and poly2
and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomialMV_${TYPENAME}_add_inplace(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME}* poly2)
");
}
?>
poly1
and *poly2
and write the result to the polynomial pointed to by poly2
.
polynomialMV_${TYPENAME}_multiply_scalar(polynomial poly, ${COEFTYPE} num)
");
}
?>
num
and poly
and write the result to poly
.
polynomialMV_${TYPENAME}_prod(polynomialMV_${TYPENAME} poly1, polynomialMV_${TYPENAME} poly2, polynomialMV_${TYPENAME}* output)
");
}
?>
poly1
and poly2
and write the result to the polynomial pointed to by output
. Initializes *output
.
polynomialMV_${TYPENAME}_order(polynomialMV_${TYPENAME} poly)
");
}
?>
poly
, using array_*_sort.
polynomialMV_${TYPENAME}_print(polynomialMV_${TYPENAME} poly)
");
}
?>
poly
.
Functions are not, strictly speaking, a C type. Instead, in this section, we describe how functions whose pointers are to be passed to the various algorithms of libinum, should be formatted.
Functions must take 3 arguments, and return an integer (a return code):
int f(TYPE* out, TYPE in, void* extra_args)
where TYPE
is the appropriate data type, e.g. double
or mpfr_t
. in
is the argument of the function, out
is made to point to \(f(\)in
\()\), and extra_args
is a pointer to void, which may contain extra arguments to be passed to the function, for example a parameter that the function depends on. For example, to implement the function \(f_\alpha(x)=x^\alpha\) using MPFR floats,
int f(mpfr_t out, mpfr_t in, void* extra_args){
int alpha=*((*int)extra_args);
mpfr_pow_ui(out, in, alpha, MPFR_RNDN);
return(0);
}
In addition, the following functions are defined
fprint_double(FILE* file, double x)
x
to file
, with as many digits as possible.
fprint_ldouble(FILE* file, long double x)
x
to file
, with as many digits as possible.
fprint_mpfr(FILE* file, mpfr_t x)
x
to file
, with as many digits as allowed by the MPFR precision.
print_datatype_info()
char
, short int
, int
, long int
and long long int
; the precision and maximal and minimal exponents of double
and long double
; the type used to store the precision and emax of MPFR floats.
Examples of programs using libinum are provided with the source code, in the doc/libinum-examples
directory. If libinum is installed on the filesystem, then the examples can also be found at /usr/share/doc/libinum/libinum-examples
.
libinum was written by Ian Jauslin.