Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-30 09:46:06

0001 //  (C) Copyright Matt Borland 2022.
0002 //  Use, modification and distribution are subject to the
0003 //  Boost Software License, Version 1.0. (See accompanying file
0004 //  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
0005 
0006 #include <cmath>
0007 #include <limits>
0008 #include <boost/math/special_functions/fpclassify.hpp>
0009 #include <boost/math/constants/constants.hpp>
0010 
0011 namespace boost { namespace math {
0012 
0013 // Calculates log(exp(x1) + exp(x2))
0014 template <typename Real>
0015 Real logaddexp(Real x1, Real x2) noexcept
0016 {
0017     using std::log1p;
0018     using std::exp;
0019     using std::abs;
0020     
0021     // Validate inputs first
0022     if (!(boost::math::isfinite)(x1))
0023     {
0024         return x1;
0025     }
0026     else if (!(boost::math::isfinite)(x2))
0027     {
0028         return x2;
0029     }
0030 
0031     const Real temp = x1 - x2;
0032 
0033     if (temp > 0)
0034     {
0035         return x1 + log1p(exp(-temp));
0036     }
0037 
0038     return x2 + log1p(exp(temp));
0039 }
0040 
0041 }} // Namespace boost::math