| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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’.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
The library ensures that the standard BSD mathematical constants are defined. For reference, here is a list of the constants:
M_EThe base of exponentials,
M_LOG2EThe base-2 logarithm of
,
M_LOG10EThe base-10 logarithm of
,
M_SQRT2The square root of two,
M_SQRT1_2The square root of one-half,
M_SQRT3The square root of three,
M_PIThe constant pi,
M_PI_2Pi divided by two,
M_PI_4Pi divided by four,
M_SQRTPIThe square root of pi,
M_2_SQRTPITwo divided by the square root of pi,
M_1_PIThe reciprocal of pi,
M_2_PITwice the reciprocal of pi,
M_LN10The natural logarithm of ten,
M_LN2The natural logarithm of two,
M_LNPIThe natural logarithm of pi,
M_EULEREuler's constant,
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro contains the IEEE representation of positive infinity,
. It is computed from the expression +1.0/0.0.
This macro contains the IEEE representation of negative infinity,
. It is computed from the expression -1.0/0.0.
This macro contains the IEEE representation of the Not-a-Number symbol,
NaN. It is computed from the ratio 0.0/0.0.
This function returns 1 if x is not-a-number.
This function returns
if x is positive infinity,
if x is negative infinity and 0 otherwise.
This function returns 1 if x is a real number, and 0 if it is infinite or not-a-number.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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).
This function computes the value of
in a way that is
accurate for small x. It provides an alternative to the BSD math
function log1p(x).
This function computes the value of
in a way that is
accurate for small x. It provides an alternative to the BSD math
function expm1(x).
This function computes the value of
in a way that avoids overflow. It provides an
alternative to the BSD math function hypot(x,y).
This function computes the value of
. It provides an
alternative to the standard math function acosh(x).
This function computes the value of
. It provides an
alternative to the standard math function asinh(x).
This function computes the value of
. It provides an
alternative to the standard math function atanh(x).
This function computes the value of
. It provides an
alternative to the standard math function ldexp(x,e).
This function splits the number
into its normalized fraction
and exponent
, such that
and
. The function returns
and stores the
exponent in
. If
is zero, both
and
are set to zero. This function provides an alternative to the standard
math function frexp(x, e).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
A common complaint about the standard C library is its lack of a function for calculating (small) integer powers. GSL provides some simple functions to fill this gap. For reasons of efficiency, these functions do not check for overflow or underflow conditions.
This routine computes the power
for integer n. The
power is computed efficiently—for example,
is computed as
, 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.
These functions can be used to compute small integer powers
,
, 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.
#include <gsl/gsl_math.h> double y = gsl_pow_4 (3.141) /* compute 3.141**4 */ |
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
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).
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro evaluates to 1 if n is odd and 0 if n is even. The argument n must be of integer type.
This macro is the opposite of GSL_IS_ODD(n). It evaluates to 1 if
n is even and 0 if n is odd. The argument n must be of
integer type.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This macro returns the maximum of a and b. It is defined as
((a) > (b) ? (a):(b)).
This macro returns the minimum of a and b. It is defined as
((a) < (b) ? (a):(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.
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.
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.
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.
| [ < ] | [ > ] | [ << ] | [ Up ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
It is sometimes useful to be able to compare two floating point numbers approximately, to allow for rounding and truncation errors. The following function implements the approximate floating-point comparison algorithm proposed by D.E. Knuth in Section 4.2.2 of Seminumerical Algorithms (3rd edition).
This function determines whether
and
are approximately
equal to a relative accuracy epsilon.
The relative accuracy is measured using an interval of size
, where
and
is the
maximum base-2 exponent of
and
as computed by the
function frexp.
If
and
lie within this interval, they are considered
approximately equal and the function returns 0. Otherwise if
, the function returns
, or if
, the function returns
.
The implementation is based on the package fcmp by T.C. Belding.
| [ << ] | [ >> ] | [Top] | [Contents] | [Index] | [ ? ] |
This document was generated by Autobuild on September, 26 2007 using texi2html 1.78.