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

Go to the SVN repository for this file.

1 #ifndef ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_FUNCTION
2 #define ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_FUNCTION
3 
4 /* $Id: njn_function.hpp 45002 2010-03-04 16:32:37Z boratyng $
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_function.hpp
32 
33 Author: John Spouge
34 
35 Contents:
36 
37 ******************************************************************************/
38 
39 #include <corelib/ncbistl.hpp>
40 
41 #include "njn_doubletype.hpp"
42 
43 #ifdef log2
44 #undef log2
45 #endif
46 
48 BEGIN_SCOPE(blast)
49 
50 BEGIN_SCOPE(Njn)
51 BEGIN_SCOPE(Function)
52 
53  template <typename T> inline T bitsToNats (T x_);
54  template <typename T> inline T natsToBits (T x_);
55  template <typename T> inline T hartleysToNats (T x_);
56  template <typename T> inline T natsToHartleys (T x_);
57  template <typename T> inline T hartleysToBits (T x_);
58  template <typename T> inline T bitsToHartleys (T x_);
59 
60  template <typename T> inline T exp2 (T x_);
61  template <typename T> inline T log2 (T x_);
62  template <typename T> inline T exp10 (T x_);
63  template <typename T> inline T log10 (T x_);
64 
65  template <typename T> inline T max (T x_, T y_);
66  template <typename T> inline T max3 (T a_, T b_, T c_);
67  template <typename T> inline T min (T x_, T y_);
68  template <typename T> inline T plus (T x_); // x_^+
69  template <typename T> inline T minus (T x_); // x_^-
70  template <typename T> inline T signum (T x_);
71  template <typename T> inline T heaviside (T x_);
72 
73  template <typename T> inline T psqrt (T x_); // square-root of x_^+
74  template <typename T> inline T square (T x_); // x_ * x_
75 
76  template <typename T> inline T bound (T x_, T xlo_, T xhi_); // the closest value to x_ in the interval [xlo_, xhi_]
77  template <typename T> inline T probability (T x_); // the closest value to x_ in the interval [0.0, 1.0]
78  template <typename T> inline T prob (T x_); // the closest value to x_ in the interval [0.0, 1.0]
79 
80  template <typename T> inline bool isProb (T x_); // the closest value to x_ in the interval [0.0, 1.0]
81 
82 //END_SCOPE(Function)
83 //END_SCOPE(Njn)
84 
85 
86 //
87 // There are no more declarations beyond this point.
88 //
89 
90 //BEGIN_SCOPE(Njn)
91 //BEGIN_SCOPE(Function)
92 
93  template <typename T> T bitsToNats (T x_) {return x_ * DoubleType::LN_2;}
94  template <typename T> T natsToBits (T x_) {return x_ / DoubleType::LN_2;}
95  template <typename T> T hartleysToNats (T x_) {return x_ * DoubleType::LN_10;}
96  template <typename T> T natsToHartleys (T x_) {return x_ / DoubleType::LN_10;}
97  template <typename T> T hartleysToBits (T x_) {return hartleysToNats (natsToBits (x_));}
98  template <typename T> T bitsToHartleys (T x_) {return bitsToNats (natsToHartleys (x_));}
99 
100  template <typename T> T exp2 (T x_) {return exp (DoubleType::LN_2 * (x_));}
101  template <typename T> T log2 (T x_) {return log (x_) / DoubleType::LN_2;}
102  template <typename T> T exp10 (T x_) {return exp (DoubleType::LN_10 * (x_));}
103  template <typename T> T log10 (T x_) {return log (x_) / DoubleType::LN_10;}
104 
105  template <typename T> T max (T x_, T y_) {return x_ > y_ ? x_ : y_;}
106  template <typename T> T max3 (T a_, T b_, T c_) {return max <T> (a_, max <T> (b_, c_));}
107  template <typename T> T min (T x_, T y_) {return x_ < y_ ? x_ : y_;}
108  template <typename T> T positive (T x_) {return max <T> (x_, static_cast <T> (0));}
109  template <typename T> T negative (T x_) {return max <T> (-x_, static_cast <T> (0));}
110  template <typename T> T signum (T x_) {return x_ > 0.0 ? 1.0 : (x_ == 0.0 ? 0.0 : -1.0);}
111  template <typename T> T heaviside (T x_) {return x_ < 0.0 ? 0.0 : 1.0;}
112 
113  template <typename T> T psqrt (T x_) {return positive <T> (sqrt (x_));}
114  template <typename T> T square (T x_) {return x_ * x_;}
115 
116  template <typename T> T bound (T x_, T xlo_, T xhi_) {
117  if (x_ < xlo_) return xlo_;
118  if (x_ < xhi_) return x_;
119  return xhi_;
120  }
121 
122  template <typename T> T probability (T x_) {return bound <T> (x_, 0.0, 1.0);}
123  template <typename T> T prob (T x_) {return probability <T> (x_);}
124 
125  template <typename T> bool isProb (T x_) {return 0.0 <= x_ && x_ <= 1.0;}; // the closest value to x_ in the interval [0.0, 1.0]
126 
127 END_SCOPE(Function)
128 END_SCOPE(Njn)
129 
130 END_SCOPE(blast)
132 
133 #endif //! ALGO_BLAST_GUMBEL_PARAMS__INCLUDED_NJN_FUNCTION
#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
The NCBI C++/STL use hints.
const double LN_2
const double LN_10
T bitsToHartleys(T x_)
T signum(T x_)
T positive(T x_)
T log2(T x_)
T hartleysToBits(T x_)
T heaviside(T x_)
T exp2(T x_)
T max(T x_, T y_)
T log10(T x_)
T prob(T x_)
T natsToHartleys(T x_)
T probability(T x_)
T natsToBits(T x_)
T hartleysToNats(T x_)
T minus(T x_)
T bitsToNats(T x_)
T exp10(T x_)
T plus(T x_)
T psqrt(T x_)
T bound(T x_, T xlo_, T xhi_)
T min(T x_, T y_)
T max3(T a_, T b_, T c_)
T negative(T x_)
T square(T x_)
bool isProb(T x_)
Modified on Wed Apr 24 14:19:40 2024 by modify_doxy.py rev. 669887