NCBI C++ ToolKit
njn_approx.hpp
Go to the documentation of this file.

Go to the SVN repository for this file.

1 #ifndef ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_APPROX
2 #define ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_APPROX
3 
4 /* $Id: njn_approx.hpp 53166 2012-02-28 16:49:36Z ucko $
5 * ===========================================================================
6 *
7 * PUBLIC DOMAIN NOTICE
8 * National Center for Biotechnology Information
9 *
10 * This software/database is a "United States Government Work" under the
11 * terms of the United States Copyright Act. It was written as part of
12 * the author's offical duties as a United States Government employee and
13 * thus cannot be copyrighted. This software/database is freely available
14 * to the public for use. The National Library of Medicine and the U.S.
15 * Government have not placed any restriction on its use or reproduction.
16 *
17 * Although all reasonable efforts have been taken to ensure the accuracy
18 * and reliability of the software and data, the NLM and the U.S.
19 * Government do not and cannot warrant the performance or results that
20 * may be obtained by using this software or data. The NLM and the U.S.
21 * Government disclaim all warranties, express or implied, including
22 * warranties of performance, merchantability or fitness for any particular
23 * purpose.
24 *
25 * Please cite the author in any work or product based on this material.
26 *
27 * ===========================================================================*/
28 
29 /*****************************************************************************
30 
31 File name: njn_approx.hpp
32 
33 Author: John Spouge
34 
35 Contents:
36 
37 ******************************************************************************/
38 
39 #include <corelib/ncbistl.hpp>
40 #include <float.h>
41 #include <math.h>
42 
44 BEGIN_SCOPE(blast)
45 
46 BEGIN_SCOPE(Njn)
47 BEGIN_SCOPE(Approx)
48 
49  // Approximation
50 
51  const float FLT_THRESHOLD = 10.0F; // Rounding threshold
52  const float FLT_ROUND = FLT_THRESHOLD * FLT_EPSILON; // Rounding error threshold
53 
54  const double DBL_THRESHOLD = 100.0; // Rounding threshold
55  const double DBL_ROUND = DBL_THRESHOLD * DBL_EPSILON; // Rounding error threshold
56 
57  template <typename T> inline bool approx (T x_, T y_, T eps_);
58  template <typename T> inline bool relApprox (T x_, T y_, T eps_);
59  template <typename T> inline bool absRelApprox (T x_, T y_, T tol_, T rtol_);
60 
61  // Rounding
62 
63  template <typename T> inline bool eq (T x_, T y_, T round_);
64  template <typename T> inline bool ge (T x_, T y_, T round_);
65  template <typename T> inline bool gt (T x_, T y_, T round_);
66  template <typename T> inline bool ne (T x_, T y_, T round_);
67  template <typename T> inline bool lt (T x_, T y_, T round_);
68  template <typename T> inline bool le (T x_, T y_, T round_);
69 
70 
71  // Approximation
72 
73  template <typename T> bool approx (T x_, T y_, T eps_) {return ::fabs (x_ - y_) <= ::fabs (eps_);}
74  template <typename T> bool relApprox (T x_, T y_, T eps_) {return approx <T> (x_, y_, eps_ * y_);}
75  template <typename T> bool absRelApprox (T x_, T y_, T tol_, T rtol_) {return approx <T> (x_, y_, tol_) || relApprox <T> (x_, y_, rtol_);}
76 
77  // Rounding
78 
79  template <typename T> bool eq (T x_, T y_, T round_) {return relApprox <T> (x_, y_, round_);}
80  template <typename T> bool ge (T x_, T y_, T round_) {return (x_ - y_) >= -(::fabs (y_)) * round_;}
81  template <typename T> bool gt (T x_, T y_, T round_) {return (x_ - y_) > (::fabs (y_)) * round_;}
82  template <typename T> bool ne (T x_, T y_, T round_) {return ! eq (x_, y_, round_);}
83  template <typename T> bool lt (T x_, T y_, T round_) {return ! ge (x_, y_, round_);}
84  template <typename T> bool le (T x_, T y_, T round_) {return ! gt (x_, y_, round_);}
85 
86 END_SCOPE(Approx)
87 END_SCOPE(Njn)
88 
89 END_SCOPE(blast)
91 
92 #endif //! ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_APPROX
#define T(s)
Definition: common.h:230
#define END_NCBI_SCOPE
End previously defined NCBI scope.
Definition: ncbistl.hpp:103
#define END_SCOPE(ns)
End the previously defined scope.
Definition: ncbistl.hpp:75
#define BEGIN_NCBI_SCOPE
Define ncbi namespace.
Definition: ncbistl.hpp:100
#define BEGIN_SCOPE(ns)
Define a new scope.
Definition: ncbistl.hpp:72
#define fabs(v)
Definition: ncbi_dispd.c:46
#define F(x)
Make a parametrized function appear to have only one variable.
Definition: ncbi_math.c:342
#define DBL_EPSILON
size of the next series term that indicates convergence in the log and polygamma functions
Definition: ncbi_math.c:61
The NCBI C++/STL use hints.
const float FLT_THRESHOLD
Definition: njn_approx.hpp:51
bool le(T x_, T y_, T round_)
Definition: njn_approx.hpp:84
bool ge(T x_, T y_, T round_)
Definition: njn_approx.hpp:80
bool lt(T x_, T y_, T round_)
Definition: njn_approx.hpp:83
const double DBL_THRESHOLD
Definition: njn_approx.hpp:54
bool relApprox(T x_, T y_, T eps_)
Definition: njn_approx.hpp:74
const float FLT_ROUND
Definition: njn_approx.hpp:52
bool approx(T x_, T y_, T eps_)
Definition: njn_approx.hpp:73
bool absRelApprox(T x_, T y_, T tol_, T rtol_)
Definition: njn_approx.hpp:75
bool eq(T x_, T y_, T round_)
Definition: njn_approx.hpp:79
const double DBL_ROUND
Definition: njn_approx.hpp:55
bool ne(T x_, T y_, T round_)
Definition: njn_approx.hpp:82
bool gt(T x_, T y_, T round_)
Definition: njn_approx.hpp:81
#define FLT_EPSILON
Definition: stdtypes.cpp:214
#define const
Definition: zconf.h:232
Modified on Fri Sep 20 14:57:57 2024 by modify_doxy.py rev. 669887