00001 /// 00002 /// \file util.cpp 00003 /// \brief Collects a variety of constants and function in namespace Util. 00004 /// 00005 /// Provides definitions for a variety of numerical constants related to 00006 /// double precision and integer arithmetic and for a small collection of 00007 /// utility functions. 00008 /// 00009 /// All are declared in namespace Util with an eye towards avoiding 00010 /// naming conflicts. 00011 /// 00012 /// \author Kent Holsinger 00013 /// \date 2005-05-18 00014 /// 00015 00016 // This file is part of MCMC++, a library for constructing C++ programs 00017 // that implement MCMC analyses of Bayesian statistical models. 00018 // Copyright (c) 2004-2006 Kent E. Holsinger 00019 // 00020 // MCMC++ is free software; you can redistribute it and/or modify 00021 // it under the terms of the GNU General Public License as published by 00022 // the Free Software Foundation; either version 2 of the License, or 00023 // (at your option) any later version. 00024 // 00025 // MCMC++ is distributed in the hope that it will be useful, 00026 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00027 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00028 // GNU General Public License for more details. 00029 // 00030 // You should have received a copy of the GNU General Public License 00031 // along with MCMC++; if not, write to the Free Software 00032 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00033 // 00034 00035 #include <cassert> 00036 // local includes 00037 #include "mcmc++/util.h" 00038 00039 /// Round a floating point number 00040 /// 00041 /// Formula: 00042 /// 00043 /// \f[\mbox{floor}(x + 0.5)\f] 00044 /// 00045 /// \param x 00046 /// 00047 double 00048 Util::round(const double x) { 00049 return floor(x + 0.5); 00050 } 00051 00052 /// Returns log_dbl_min if x < log_dbl_min 00053 /// 00054 /// \param x The logarithm to check 00055 /// 00056 double 00057 Util::safeLog(const double x) { 00058 return (x > log_dbl_min) ? x : log_dbl_min; 00059 } 00060 00061 /// Returns \f$x^2\f$ 00062 /// 00063 /// \param x 00064 /// 00065 double 00066 Util::sqr(const double x) { 00067 return x*x; 00068 } 00069
1.5.1