This chapter describes basic mathematical functions. Some of these
functions are present in system libraries, but the alternative versions
given here can be used as a substitute when the system functions are not
available.
The functions and macros described in this chapter are defined in the
header file `gsl_math.h'.
The following routines provide portable implementations of functions
found in the BSD math library. When native versions are not available
the functions described here can be used instead. The substitution can
be made automatically if you use autoconf to compile your
application (see section Portability functions).
Function: double gsl_log1p(const double x)
This function computes the value of \log(1+x) in a way that is
accurate for small x. It provides an alternative to the BSD math
function log1p(x).
Function: double gsl_expm1(const double x)
This function computes the value of \exp(x)-1 in a way that is
accurate for small x. It provides an alternative to the BSD math
function expm1(x).
A common complaint about the standard C library is its lack of a
function for calculating (small) integer powers. GSL provides a simple
functions to fill this gap. For reasons of efficiency, these functions
do not check for overflow or underflow conditions.
Function: double gsl_pow_int(double x, int n)
This routine computes the power x^n for integer n. The
power is computed using the minimum number of multiplications. For
example, x^8 is computed as ((x^2)^2)^2, requiring only 3
multiplications. A version of this function which also computes the
numerical error in the result is available as gsl_sf_pow_int_e.
Function: double gsl_pow_2(const double x)
Function: double gsl_pow_3(const double x)
Function: double gsl_pow_4(const double x)
Function: double gsl_pow_5(const double x)
Function: double gsl_pow_6(const double x)
Function: double gsl_pow_7(const double x)
Function: double gsl_pow_8(const double x)
Function: double gsl_pow_9(const double x)
These functions can be used to compute small integer powers x^2,
x^3, etc. efficiently. The functions will be inlined when
possible so that use of these functions should be as efficient as
explicitly writing the corresponding product expression.
This macro returns the sign of x. It is defined as ((x) >= 0
? 1 : -1). Note that with this definition the sign of zero is positive
(regardless of its IEEE sign bit).
This macro returns the maximum of a and b. It is defined as
((a) > (b) ? (a):(b)).
Macro:GSL_MIN(a, b)
This macro returns the minimum of a and b. It is defined as
((a) < (b) ? (a):(b)).
Function: extern inline double GSL_MAX_DBL(double a, double b)
This function returns the maximum of the double precision numbers
a and b using an inline function. The use of a function
allows for type checking of the arguments as an extra safety feature. On
platforms where inline functions are not available the macro
GSL_MAX will be automatically substituted.
Function: extern inline double GSL_MIN_DBL(double a, double b)
This function returns the minimum of the double precision numbers
a and b using an inline function. The use of a function
allows for type checking of the arguments as an extra safety feature. On
platforms where inline functions are not available the macro
GSL_MIN will be automatically substituted.
Function: extern inline int GSL_MAX_INT(int a, int b)
Function: extern inline int GSL_MIN_INT(int a, int b)
These functions return the maximum or minimum of the integers a
and b using an inline function. On platforms where inline
functions are not available the macros GSL_MAX or GSL_MIN
will be automatically substituted.
Function: extern inline long double GSL_MAX_LDBL(long double a, long double b)
Function: extern inline long double GSL_MIN_LDBL(long double a, long double b)
These functions return the maximum or minimum of the long doubles a
and b using an inline function. On platforms where inline
functions are not available the macros GSL_MAX or GSL_MIN
will be automatically substituted.