Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:40:23

0001 //  (C) Copyright John Maddock 2006.
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 #ifndef BOOST_MATH_SQRT1PM1
0007 #define BOOST_MATH_SQRT1PM1
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/math/special_functions/math_fwd.hpp>
0014 #include <boost/math/special_functions/log1p.hpp>
0015 #include <boost/math/special_functions/expm1.hpp>
0016 
0017 //
0018 // This algorithm computes sqrt(1+x)-1 for small x:
0019 //
0020 
0021 namespace boost{ namespace math{
0022 
0023 template <class T, class Policy>
0024 inline typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy& pol)
0025 {
0026    typedef typename tools::promote_args<T>::type result_type;
0027    BOOST_MATH_STD_USING
0028 
0029    if(fabs(result_type(val)) > result_type(0.75))
0030       return sqrt(1 + result_type(val)) - 1;
0031    return boost::math::expm1(boost::math::log1p(val, pol) / 2, pol);
0032 }
0033 
0034 template <class T>
0035 inline typename tools::promote_args<T>::type sqrt1pm1(const T& val)
0036 {
0037    return sqrt1pm1(val, policies::policy<>());
0038 }
0039 
0040 } // namespace math
0041 } // namespace boost
0042 
0043 #endif // BOOST_MATH_SQRT1PM1
0044 
0045 
0046 
0047 
0048