File indexing completed on 2025-09-17 08:36:24
0001
0002
0003
0004
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/tools/config.hpp>
0014 #include <boost/math/special_functions/math_fwd.hpp>
0015 #include <boost/math/special_functions/log1p.hpp>
0016 #include <boost/math/special_functions/expm1.hpp>
0017
0018
0019
0020
0021
0022 namespace boost{ namespace math{
0023
0024 template <class T, class Policy>
0025 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy& pol)
0026 {
0027 typedef typename tools::promote_args<T>::type result_type;
0028 BOOST_MATH_STD_USING
0029
0030 if(fabs(result_type(val)) > result_type(0.75))
0031 return sqrt(1 + result_type(val)) - 1;
0032 return boost::math::expm1(boost::math::log1p(val, pol) / 2, pol);
0033 }
0034
0035 template <class T>
0036 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sqrt1pm1(const T& val)
0037 {
0038 return sqrt1pm1(val, policies::policy<>());
0039 }
0040
0041 }
0042 }
0043
0044 #endif
0045
0046
0047
0048
0049