◆ hypot()

IEEEValue boost::simd::hypot ( IEEEValue const &  x,
IEEEValue const &  y 
)

This function object computes the hypothenuse length: \((x^2 + y^2)^{1/2}\).

Header <boost/simd/function/hypot.hpp>
Decorators
  • pedantic_ with this decorator provisions are made to avoid overflow and to compute hypot as accurately as possible in any cases.
  • std_ call std::hypot
See also
sqr, sqrt
Example:
#include <boost/simd/arithmetic.hpp>
#include <boost/simd/pack.hpp>
#include <boost/simd/constant/valmax.hpp>
#include <iostream>
namespace bs = boost::simd;
using pack_ft = bs::pack <float, 4>;
int main()
{
pack_ft pf = { 3.0f, -2.0f, -3.0f, bs::Valmax<float>() };
pack_ft qf = { 4.0f, -1.0f, -3.0f, 0.0f };
std::cout
<< "---- simd" << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> bs::hypot(pf, qf) = " << bs::hypot(pf, qf) << '\n'
<< " -> bs::pedantic_(bs::hypot)(pf, qf) = " << bs::pedantic_(bs::hypot)(pf, qf) << '\n';
float xf = 3.0f, yf = 4.0f;
std::cout
<< "---- scalar" << '\n'
<< " xf = " << xf << '\n'
<< " yf = " << yf << '\n'
<< " -> bs::hypot(xf, yf) = " << bs::hypot(xf, yf) << '\n'
<< " -> bs::pedantic_(bs::hypot)(xf, yf) = " << bs::pedantic_(bs::hypot)(xf, yf) << '\n';
return 0;
}
Possible output:
---- simd
<- pf = (3, -2, -3, 3.40282e+38)
<- qf = (4, -1, -3, 0)
-> bs::hypot(pf, qf) = (5, 2.23607, 4.24264, inf)
-> bs::pedantic_(bs::hypot)(pf, qf) = (5, 2.23607, 4.24264, 3.40282e+38)
---- scalar
xf = 3
yf = 4
-> bs::hypot(xf, yf) = 5
-> bs::pedantic_(bs::hypot)(xf, yf) = 5