Chris@16: // (C) Copyright John Maddock 2006. Chris@16: // Use, modification and distribution are subject to the Chris@16: // Boost Software License, Version 1.0. (See accompanying file Chris@16: // LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) Chris@16: Chris@16: #ifndef BOOST_MATH_SQRT1PM1 Chris@16: #define BOOST_MATH_SQRT1PM1 Chris@16: Chris@16: #ifdef _MSC_VER Chris@16: #pragma once Chris@16: #endif Chris@16: Chris@101: #include Chris@16: #include Chris@16: #include Chris@16: Chris@16: // Chris@16: // This algorithm computes sqrt(1+x)-1 for small x: Chris@16: // Chris@16: Chris@16: namespace boost{ namespace math{ Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type sqrt1pm1(const T& val, const Policy& pol) Chris@16: { Chris@16: typedef typename tools::promote_args::type result_type; Chris@16: BOOST_MATH_STD_USING Chris@16: Chris@16: if(fabs(result_type(val)) > 0.75) Chris@16: return sqrt(1 + result_type(val)) - 1; Chris@16: return boost::math::expm1(boost::math::log1p(val, pol) / 2, pol); Chris@16: } Chris@16: Chris@16: template Chris@16: inline typename tools::promote_args::type sqrt1pm1(const T& val) Chris@16: { Chris@16: return sqrt1pm1(val, policies::policy<>()); Chris@16: } Chris@16: Chris@16: } // namespace math Chris@16: } // namespace boost Chris@16: Chris@16: #endif // BOOST_MATH_SQRT1PM1 Chris@16: Chris@16: Chris@16: Chris@16: Chris@16: