brintos

brintos / llvm-project-archived public Read only

0
0
Text · 1.2 KiB · 4d8aeb3 Raw
50 lines · plain
1//  (C) Copyright John Maddock 2006.2//  Use, modification and distribution are subject to the3//  Boost Software License, Version 1.0. (See accompanying file4//  LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)5 6#ifndef BOOST_MATH_SQRT1PM17#define BOOST_MATH_SQRT1PM18 9#ifdef _MSC_VER10#pragma once11#endif12 13#include <boost/math/tools/config.hpp>14#include <boost/math/special_functions/math_fwd.hpp>15#include <boost/math/special_functions/log1p.hpp>16#include <boost/math/special_functions/expm1.hpp>17 18//19// This algorithm computes sqrt(1+x)-1 for small x:20//21 22namespace boost{ namespace math{23 24template <class T, class Policy>25BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sqrt1pm1(const T& val, const Policy& pol)26{27   typedef typename tools::promote_args<T>::type result_type;28   BOOST_MATH_STD_USING29 30   if(fabs(result_type(val)) > result_type(0.75))31      return sqrt(1 + result_type(val)) - 1;32   return boost::math::expm1(boost::math::log1p(val, pol) / 2, pol);33}34 35template <class T>36BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T>::type sqrt1pm1(const T& val)37{38   return sqrt1pm1(val, policies::policy<>());39}40 41} // namespace math42} // namespace boost43 44#endif // BOOST_MATH_SQRT1PM145 46 47 48 49 50