NCBI C++ ToolKit
Macros | Functions
ncbi_math.h File Reference

Prototypes for portable math library (ported from C Toolkit) More...

#include <algo/blast/core/ncbi_std.h>
#include <algo/blast/core/blast_export.h>
+ Include dependency graph for ncbi_math.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Go to the SVN repository for this file.

Macros

#define LOGDERIV_ORDER_MAX   4
 Number of derivatives of log(x) to carry in gamma-related computations. More...
 
#define POLYGAMMA_ORDER_MAX   LOGDERIV_ORDER_MAX
 Number of derivatives of polygamma(x) to carry in gamma-related computations for non-integral values of x. More...
 
#define NCBIMATH_PI   3.1415926535897932384626433832795
 value of pi is only used in gamma-related computations More...
 
#define NCBIMATH_LN2   0.69314718055994530941723212145818
 Natural log(2) More...
 
#define NCBIMATH_LNPI   1.1447298858494001741434273513531
 Natural log(PI) More...
 

Functions

double BLAST_Log1p (double x)
 Natural logarithm with shifted input. More...
 
double BLAST_Expm1 (double x)
 Exponentional with base e. More...
 
double BLAST_Factorial (Int4 n)
 Factorial function. More...
 
double BLAST_LnFactorial (double x)
 Logarithm of the factorial. More...
 
double BLAST_LnGammaInt (Int4 n)
 log(gamma(n)), integral n More...
 
double BLAST_RombergIntegrate (double(*f)(double, void *), void *fargs, double p, double q, double eps, Int4 epsit, Int4 itmin)
 Romberg numerical integrator. More...
 
Int4 BLAST_Gcd (Int4 a, Int4 b)
 Greatest common divisor. More...
 
Int4 BLAST_Gdb3 (Int4 *a, Int4 *b, Int4 *c)
 Divide 3 numbers by their greatest common divisor. More...
 
long BLAST_Nint (double x)
 Nearest integer. More...
 
double BLAST_Powi (double x, Int4 n)
 Integral power of x. More...
 
double BLAST_Erf (double x)
 The error function of x: the integral from 0 to x of e(-t*t) dt, scaled by 2/sqrt(pi) to fall within the range (-1,1). More...
 
double BLAST_ErfC (double x)
 The complementary error function of x: 1 - erf(x), but calculated more accurately for large x (where erf(x) approaches unity). More...
 

Detailed Description

Prototypes for portable math library (ported from C Toolkit)

Definition in file ncbi_math.h.

Macro Definition Documentation

◆ LOGDERIV_ORDER_MAX

#define LOGDERIV_ORDER_MAX   4

Number of derivatives of log(x) to carry in gamma-related computations.

Definition at line 152 of file ncbi_math.h.

◆ NCBIMATH_LN2

#define NCBIMATH_LN2   0.69314718055994530941723212145818

Natural log(2)

Definition at line 161 of file ncbi_math.h.

◆ NCBIMATH_LNPI

#define NCBIMATH_LNPI   1.1447298858494001741434273513531

Natural log(PI)

Definition at line 163 of file ncbi_math.h.

◆ NCBIMATH_PI

#define NCBIMATH_PI   3.1415926535897932384626433832795

value of pi is only used in gamma-related computations

Definition at line 158 of file ncbi_math.h.

◆ POLYGAMMA_ORDER_MAX

#define POLYGAMMA_ORDER_MAX   LOGDERIV_ORDER_MAX

Number of derivatives of polygamma(x) to carry in gamma-related computations for non-integral values of x.

Definition at line 155 of file ncbi_math.h.

Function Documentation

◆ BLAST_Erf()

double BLAST_Erf ( double  x)

The error function of x: the integral from 0 to x of e(-t*t) dt, scaled by 2/sqrt(pi) to fall within the range (-1,1).

◆ BLAST_ErfC()

double BLAST_ErfC ( double  x)

The complementary error function of x: 1 - erf(x), but calculated more accurately for large x (where erf(x) approaches unity).

◆ BLAST_Expm1()

double BLAST_Expm1 ( double  x)

Exponentional with base e.

Parameters
xinput operand
Returns
exp(x) - 1

Definition at line 33 of file ncbi_math.c.

References ABS.

Referenced by BLAST_KarlinEtoP(), BlastKarlinLHtoK(), s_BlastSumP(), and s_BlastSumPCalc().

◆ BLAST_Factorial()

double BLAST_Factorial ( Int4  n)

Factorial function.

Parameters
ninput operand
Returns
(double)(1 * 2 * 3 * ... * n)

Definition at line 312 of file ncbi_math.c.

References DIM, kPrecomputedFactorial, n, and s_LnGamma().

Referenced by s_GeneralLnGamma(), and s_PolyGamma().

◆ BLAST_Gcd()

Int4 BLAST_Gcd ( Int4  a,
Int4  b 
)

Greatest common divisor.

Parameters
aFirst operand (any integer)
bSecond operand (any integer)
Returns
The largest integer that evenly divides a and b

Definition at line 405 of file ncbi_math.c.

References a, ABS, and b.

Referenced by BLAST_Gdb3(), Blast_KarlinLambdaNR(), BlastKarlinLHtoK(), and s_GetNuclValuesArray().

◆ BLAST_Gdb3()

Int4 BLAST_Gdb3 ( Int4 a,
Int4 b,
Int4 c 
)

Divide 3 numbers by their greatest common divisor.

Parameters
aFirst integer [in] [out]
bSecond integer [in] [out]
cThird integer [in] [out]
Returns
The greatest common divisor

Definition at line 422 of file ncbi_math.c.

References a, b, BLAST_Gcd(), and g().

Referenced by BLAST_AffineGreedyAlign(), and s_BlastGreedyAlignMemAlloc().

◆ BLAST_LnFactorial()

double BLAST_LnFactorial ( double  x)

Logarithm of the factorial.

Parameters
xinput operand
Returns
log(1 * 2 * 3 * ... * x)

Definition at line 473 of file ncbi_math.c.

References s_LnGamma().

Referenced by BLAST_LargeGapSumE(), BLAST_SmallGapSumE(), and BLAST_UnevenGapSumE().

◆ BLAST_LnGammaInt()

double BLAST_LnGammaInt ( Int4  n)

log(gamma(n)), integral n

Parameters
ninput operand
Returns
log(1 * 2 * 3 * ... (n-1))

Definition at line 323 of file ncbi_math.c.

References DIM, kPrecomputedFactorial, log, n, and s_LnGamma().

Referenced by s_BlastSumP(), and s_BlastSumPCalc().

◆ BLAST_Log1p()

double BLAST_Log1p ( double  x)

Natural logarithm with shifted input.

Parameters
xinput operand (x > -1)
Returns
log(x+1)

Definition at line 64 of file ncbi_math.c.

References ABS, DBL_EPSILON, i, and log.

Referenced by BLAST_KarlinPtoE().

◆ BLAST_Nint()

long BLAST_Nint ( double  x)

◆ BLAST_Powi()

double BLAST_Powi ( double  x,
Int4  n 
)

Integral power of x.

Parameters
xfloating-point base of the exponential
n(integer) exponent
Returns
x multiplied by itself n times

Definition at line 444 of file ncbi_math.c.

References n.

Referenced by BLAST_GapDecayDivisor(), BlastKarlinLtoH(), s_GeneralLnGamma(), and s_PolyGamma().

◆ BLAST_RombergIntegrate()

double BLAST_RombergIntegrate ( double(*)(double, void *)  f,
void *  fargs,
double  p,
double  q,
double  eps,
Int4  epsit,
Int4  itmin 
)

Romberg numerical integrator.

Parameters
fPointer to the function to integrate; the first argument is the variable to integrate over, the second is a pointer to a list of additional arguments that f may need
fargsPointer to an array of extra arguments or parameters needed to compute the function to be integrated. None of the items in this list may vary over the region of integration
pLeft-hand endpoint of the integration interval
qRight-hand endpoint of the integration interval (q is assumed > p)
epsThe relative error tolerance that indicates convergence
epsitThe number of consecutive diagonal entries in the Romberg array whose relative difference must be less than eps before convergence is assumed. This is presently limited to 1, 2, or 3
itminThe minimum number of diagnonal Romberg entries that will be computed
Returns
The computed integral of f() between p and q

Definition at line 346 of file ncbi_math.c.

References ABS, F, i, MAX, MAX_DIAGS, MIN, and n.

Referenced by s_BlastSumPCalc(), and s_InnerIntegralCback().

Modified on Thu Jun 13 17:30:00 2024 by modify_doxy.py rev. 669887