NCBI C++ ToolKit
ncbi_math.h
Go to the documentation of this file.

Go to the SVN repository for this file.

1 /* $Id: ncbi_math.h 52835 2012-02-01 16:20:19Z ucko $
2  * ===========================================================================
3  *
4  * PUBLIC DOMAIN NOTICE
5  * National Center for Biotechnology Information
6  *
7  * This software/database is a "United States Government Work" under the
8  * terms of the United States Copyright Act. It was written as part of
9  * the author's official duties as a United States Government employee and
10  * thus cannot be copyrighted. This software/database is freely available
11  * to the public for use. The National Library of Medicine and the U.S.
12  * Government have not placed any restriction on its use or reproduction.
13  *
14  * Although all reasonable efforts have been taken to ensure the accuracy
15  * and reliability of the software and data, the NLM and the U.S.
16  * Government do not and cannot warrant the performance or results that
17  * may be obtained by using this software or data. The NLM and the U.S.
18  * Government disclaim all warranties, express or implied, including
19  * warranties of performance, merchantability or fitness for any particular
20  * purpose.
21  *
22  * Please cite the author in any work or product based on this material.
23  *
24  * ===========================================================================
25  *
26  * Authors: Gish, Kans, Ostell, Schuler
27  *
28  * Version Creation Date: 10/23/91
29  *
30  * ==========================================================================
31  */
32 
33 /** @file ncbi_math.h
34  * Prototypes for portable math library (ported from C Toolkit)
35  */
36 
37 #ifndef ALGO_BLAST_CORE__NCBIMATH
38 #define ALGO_BLAST_CORE__NCBIMATH
39 
42 
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46 
47 /** Natural logarithm with shifted input
48  * @param x input operand (x > -1)
49  * @return log(x+1)
50  */
52 double BLAST_Log1p (double x);
53 
54 /** Exponentional with base e
55  * @param x input operand
56  * @return exp(x) - 1
57  */
59 double BLAST_Expm1 (double x);
60 
61 /** Factorial function
62  * @param n input operand
63  * @return (double)(1 * 2 * 3 * ... * n)
64  */
66 double BLAST_Factorial(Int4 n);
67 
68 /** Logarithm of the factorial
69  * @param x input operand
70  * @return log(1 * 2 * 3 * ... * x)
71  */
73 double BLAST_LnFactorial (double x);
74 
75 /** log(gamma(n)), integral n
76  * @param n input operand
77  * @return log(1 * 2 * 3 * ... (n-1))
78  */
80 double BLAST_LnGammaInt (Int4 n);
81 
82 /** Romberg numerical integrator
83  * @param f Pointer to the function to integrate; the first argument
84  * is the variable to integrate over, the second is a pointer
85  * to a list of additional arguments that f may need
86  * @param fargs Pointer to an array of extra arguments or parameters
87  * needed to compute the function to be integrated. None
88  * of the items in this list may vary over the region
89  * of integration
90  * @param p Left-hand endpoint of the integration interval
91  * @param q Right-hand endpoint of the integration interval
92  * (q is assumed > p)
93  * @param eps The relative error tolerance that indicates convergence
94  * @param epsit The number of consecutive diagonal entries in the
95  * Romberg array whose relative difference must be less than
96  * eps before convergence is assumed. This is presently
97  * limited to 1, 2, or 3
98  * @param itmin The minimum number of diagnonal Romberg entries that
99  * will be computed
100  * @return The computed integral of f() between p and q
101  */
103 double BLAST_RombergIntegrate (double (*f) (double, void*),
104  void* fargs, double p, double q,
105  double eps, Int4 epsit, Int4 itmin);
106 
107 /** Greatest common divisor
108  * @param a First operand (any integer)
109  * @param b Second operand (any integer)
110  * @return The largest integer that evenly divides a and b
111  */
114 
115 /** Divide 3 numbers by their greatest common divisor
116  * @param a First integer [in] [out]
117  * @param b Second integer [in] [out]
118  * @param c Third integer [in] [out]
119  * @return The greatest common divisor
120  */
122 Int4 BLAST_Gdb3(Int4* a, Int4* b, Int4* c);
123 
124 /** Nearest integer
125  * @param x Input to round (rounded value must be representable
126  * as a 32-bit signed integer)
127  * @return floor(x + 0.5);
128  */
130 long BLAST_Nint (double x);
131 
132 /** Integral power of x
133  * @param x floating-point base of the exponential
134  * @param n (integer) exponent
135  * @return x multiplied by itself n times
136  */
138 double BLAST_Powi (double x, Int4 n);
139 
140 /** The error function of x: the integral from 0 to x of e(-t*t) dt,
141  * scaled by 2/sqrt(pi) to fall within the range (-1,1). */
143 double BLAST_Erf (double x);
144 
145 /** The complementary error function of x: 1 - erf(x), but calculated
146  * more accurately for large x (where erf(x) approaches unity). */
148 double BLAST_ErfC (double x);
149 
150 /** Number of derivatives of log(x) to carry in gamma-related
151  computations */
152 #define LOGDERIV_ORDER_MAX 4
153 /** Number of derivatives of polygamma(x) to carry in gamma-related
154  computations for non-integral values of x */
155 #define POLYGAMMA_ORDER_MAX LOGDERIV_ORDER_MAX
156 
157 /** value of pi is only used in gamma-related computations */
158 #define NCBIMATH_PI 3.1415926535897932384626433832795
159 
160 /** Natural log(2) */
161 #define NCBIMATH_LN2 0.69314718055994530941723212145818
162 /** Natural log(PI) */
163 #define NCBIMATH_LNPI 1.1447298858494001741434273513531
164 
165 #ifdef __cplusplus
166 }
167 #endif
168 
169 #endif /* !ALGO_BLAST_CORE__NCBIMATH */
Defines to provide correct exporting from BLAST DLL in Windows.
#define NCBI_XBLAST_EXPORT
NULL operations for other cases.
Definition: blast_export.h:65
int32_t Int4
4-byte (32-bit) signed integer
Definition: ncbitype.h:102
yy_size_t n
unsigned int a
Definition: ncbi_localip.c:102
double BLAST_Log1p(double x)
Natural logarithm with shifted input.
Definition: ncbi_math.c:64
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 ...
Int4 BLAST_Gdb3(Int4 *a, Int4 *b, Int4 *c)
Divide 3 numbers by their greatest common divisor.
Definition: ncbi_math.c:422
long BLAST_Nint(double x)
Nearest integer.
Definition: ncbi_math.c:437
double BLAST_ErfC(double x)
The complementary error function of x: 1 - erf(x), but calculated more accurately for large x (where ...
double BLAST_Powi(double x, Int4 n)
Integral power of x.
Definition: ncbi_math.c:444
double BLAST_Expm1(double x)
Exponentional with base e.
Definition: ncbi_math.c:33
double BLAST_LnFactorial(double x)
Logarithm of the factorial.
Definition: ncbi_math.c:473
double BLAST_RombergIntegrate(double(*f)(double, void *), void *fargs, double p, double q, double eps, Int4 epsit, Int4 itmin)
Romberg numerical integrator.
Definition: ncbi_math.c:346
double BLAST_Factorial(Int4 n)
Factorial function.
Definition: ncbi_math.c:312
Int4 BLAST_Gcd(Int4 a, Int4 b)
Greatest common divisor.
Definition: ncbi_math.c:405
double BLAST_LnGammaInt(Int4 n)
log(gamma(n)), integral n
Definition: ncbi_math.c:323
Type and macro definitions from C toolkit that are not defined in C++ toolkit.
double f(double x_, const double &y_)
Definition: njn_root.hpp:188
Modified on Tue May 14 16:19:01 2024 by modify_doxy.py rev. 669887