1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include <cmath>
- #include <limits>
- #include <boost/math/special_functions/fpclassify.hpp>
- #include <boost/math/constants/constants.hpp>
- namespace boost { namespace math {
- template <typename Real>
- Real logaddexp(Real x1, Real x2) noexcept
- {
- using std::log1p;
- using std::exp;
- using std::abs;
-
-
- if (!(boost::math::isfinite)(x1))
- {
- return x1;
- }
- else if (!(boost::math::isfinite)(x2))
- {
- return x2;
- }
- const Real temp = x1 - x2;
- if (temp > 0)
- {
- return x1 + log1p(exp(-temp));
- }
- return x2 + log1p(exp(temp));
- }
- }}
|