File indexing completed on 2025-11-04 09:51:21
0001 
0002 
0003 
0004 
0005 
0006 #ifndef BOOST_MATH_HYPOT_INCLUDED
0007 #define BOOST_MATH_HYPOT_INCLUDED
0008 
0009 #ifdef _MSC_VER
0010 #pragma once
0011 #endif
0012 
0013 #include <boost/math/tools/config.hpp>
0014 #include <boost/math/tools/precision.hpp>
0015 #include <boost/math/tools/numeric_limits.hpp>
0016 #include <boost/math/tools/type_traits.hpp>
0017 #include <boost/math/policies/error_handling.hpp>
0018 #include <boost/math/special_functions/math_fwd.hpp>
0019 
0020 namespace boost{ namespace math{ namespace detail{
0021 
0022 template <class T, class Policy>
0023 BOOST_MATH_GPU_ENABLED T hypot_imp(T x, T y, const Policy& pol)
0024 {
0025    
0026    
0027    
0028    BOOST_MATH_STD_USING
0029 
0030    x = fabs(x);
0031    y = fabs(y);
0032 
0033 #ifdef _MSC_VER
0034 #pragma warning(push)
0035 #pragma warning(disable: 4127)
0036 #endif
0037    
0038    if(boost::math::numeric_limits<T>::has_infinity
0039       && ((x == boost::math::numeric_limits<T>::infinity())
0040       || (y == boost::math::numeric_limits<T>::infinity())))
0041       return policies::raise_overflow_error<T>("boost::math::hypot<%1%>(%1%,%1%)", nullptr, pol);
0042 #ifdef _MSC_VER
0043 #pragma warning(pop)
0044 #endif
0045 
0046    if(y > x)
0047       BOOST_MATH_GPU_SAFE_SWAP(x, y);
0048 
0049    if(x * tools::epsilon<T>() >= y)
0050       return x;
0051 
0052    T rat = y / x;
0053    return x * sqrt(1 + rat*rat);
0054 } 
0055 
0056 }
0057 
0058 template <class T1, class T2>
0059 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type
0060    hypot(T1 x, T2 y)
0061 {
0062    typedef typename tools::promote_args<T1, T2>::type result_type;
0063    return detail::hypot_imp(
0064       static_cast<result_type>(x), static_cast<result_type>(y), policies::policy<>());
0065 }
0066 
0067 template <class T1, class T2, class Policy>
0068 BOOST_MATH_GPU_ENABLED inline typename tools::promote_args<T1, T2>::type
0069    hypot(T1 x, T2 y, const Policy& pol)
0070 {
0071    typedef typename tools::promote_args<T1, T2>::type result_type;
0072    return detail::hypot_imp(
0073       static_cast<result_type>(x), static_cast<result_type>(y), pol);
0074 }
0075 
0076 } 
0077 } 
0078 
0079 #endif 
0080 
0081 
0082