IT++ Logo
log_exp.cpp
Go to the documentation of this file.
00001 
00029 #include <itpp/base/math/log_exp.h>
00030 #include <itpp/base/itcompat.h>
00031 
00032 namespace itpp
00033 {
00034 
00035 // log-2 of the elements
00036 vec log2(const vec &x) { return apply_function<double>(::log2, x); }
00037 mat log2(const mat &x) { return apply_function<double>(::log2, x); }
00038 
00039 // Safe substitute for <tt>log(exp(log_a) + exp(log_b))</tt>
00040 double log_add(double log_a, double log_b)
00041 {
00042   if (log_a < log_b) {
00043     double tmp = log_a;
00044     log_a = log_b;
00045     log_b = tmp;
00046   }
00047   double negdelta = log_b - log_a;
00048   if ((negdelta < log_double_min) || std::isnan(negdelta))
00049     return log_a;
00050   else
00051     return (log_a + log1p(std::exp(negdelta)));
00052 }
00053 
00054 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SourceForge Logo

Generated on Wed Jul 27 2011 16:27:04 for IT++ by Doxygen 1.7.4