#ifndef INCLUDED_NJN_FUNCTION #define INCLUDED_NJN_FUNCTION /* $Id: $ * =========================================================================== * * PUBLIC DOMAIN NOTICE * National Center for Biotechnology Information * * This software/database is a "United States Government Work" under the * terms of the United States Copyright Act. It was written as part of * the author's offical duties as a United States Government employee and * thus cannot be copyrighted. This software/database is freely available * to the public for use. The National Library of Medicine and the U.S. * Government have not placed any restriction on its use or reproduction. * * Although all reasonable efforts have been taken to ensure the accuracy * and reliability of the software and data, the NLM and the U.S. * Government do not and cannot warrant the performance or results that * may be obtained by using this software or data. The NLM and the U.S. * Government disclaim all warranties, express or implied, including * warranties of performance, merchantability or fitness for any particular * purpose. * * Please cite the author in any work or product based on this material. * * ===========================================================================*/ /***************************************************************************** File name: njn_function.hpp Author: John Spouge Contents: ******************************************************************************/ #include "njn_doubletype.hpp" namespace Njn { namespace Function { template inline T bitsToNats (T x_); template inline T natsToBits (T x_); template inline T hartleysToNats (T x_); template inline T natsToHartleys (T x_); template inline T hartleysToBits (T x_); template inline T bitsToHartleys (T x_); template inline T exp2 (T x_); template inline T log2 (T x_); template inline T exp10 (T x_); template inline T log10 (T x_); template inline T max (T x_, T y_); template inline T max3 (T a_, T b_, T c_); template inline T min (T x_, T y_); template inline T plus (T x_); // x_^+ template inline T minus (T x_); // x_^- template inline T signum (T x_); template inline T heaviside (T x_); template inline T psqrt (T x_); // square-root of x_^+ template inline T square (T x_); // x_ * x_ template inline T bound (T x_, T xlo_, T xhi_); // the closest value to x_ in the interval [xlo_, xhi_] template inline T probability (T x_); // the closest value to x_ in the interval [0.0, 1.0] template inline T prob (T x_); // the closest value to x_ in the interval [0.0, 1.0] template inline bool isProb (T x_); // the closest value to x_ in the interval [0.0, 1.0] // // There are no more declarations beyond this point. // template T bitsToNats (T x_) {return x_ * DoubleType::LN_2;} template T natsToBits (T x_) {return x_ / DoubleType::LN_2;} template T hartleysToNats (T x_) {return x_ * DoubleType::LN_10;} template T natsToHartleys (T x_) {return x_ / DoubleType::LN_10;} template T hartleysToBits (T x_) {return hartleysToNats (natsToBits (x_));} template T bitsToHartleys (T x_) {return bitsToNats (natsToHartleys (x_));} template T exp2 (T x_) {return exp (DoubleType::LN_2 * (x_));} template T log2 (T x_) {return log (x_) / DoubleType::LN_2;} template T exp10 (T x_) {return exp (DoubleType::LN_10 * (x_));} template T log10 (T x_) {return log (x_) / DoubleType::LN_10;} template T max (T x_, T y_) {return x_ > y_ ? x_ : y_;} template T max3 (T a_, T b_, T c_) {return max (a_, max (b_, c_));} template T min (T x_, T y_) {return x_ < y_ ? x_ : y_;} template T positive (T x_) {return max (x_, static_cast (0));} template T negative (T x_) {return max (-x_, static_cast (0));} template T signum (T x_) {return x_ > 0.0 ? 1.0 : (x_ == 0.0 ? 0.0 : -1.0);} template T heaviside (T x_) {return x_ < 0.0 ? 0.0 : 1.0;} template T psqrt (T x_) {return positive (sqrt (x_));} template T square (T x_) {return x_ * x_;} template T bound (T x_, T xlo_, T xhi_) { if (x_ < xlo_) return xlo_; if (x_ < xhi_) return x_; return xhi_; } template T probability (T x_) {return bound (x_, 0.0, 1.0);} template T prob (T x_) {return probability (x_);} template bool isProb (T x_) {return 0.0 <= x_ && x_ <= 1.0;}/*sls deleted;*/ // the closest value to x_ in the interval [0.0, 1.0] } } #endif //! INCLUDED