E.V.E
v2022.03.00

◆ sqr

eve::sqr = {}
inlineconstexpr

Computes the square of the parameter.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
T sqr(T x) noexcept;
}
constexpr callable_sqr_ sqr
Computes the square of the parameter.
Definition: sqr.hpp:87
Definition: all_of.hpp:22

Parameters

Return value

value containing the elementwise square of x if it is representable in this type.

Note
For integral signed values if eve::saturated(eve::abs)(x) is greater than eve::Sqrtvalmax(as(x)) the corresponding element result is undefined.

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft pf = {-1.0f, 2.0f, -3.0f, 182.0f};
wide_it pi = {-1, 2, -3, 182};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> sqr(pf) = " << eve::sqr(pf) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> saturated(sqr)(pi) = " << eve::saturated(eve::sqr)(pi) << '\n'
<< "-> sqr(pi) = " << eve::sqr(pi) << '\n';
float xf = -32768.0f;
std::int16_t xi = -32768;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> sqr(xf) = " << eve::sqr(xf) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> saturated(sqr)(xi) = " << eve::saturated(eve::sqr)(xi) << '\n'
<< "-> sqr(xi) = " << eve::sqr(xi) << '\n';
return 0;
}
constexpr saturated_type const saturated
Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
Definition: saturated.hpp:68
constexpr callable_pi_ pi
Callable object computing the constant .
Definition: pi.hpp:49
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve;sqr[mask](x) provides a masked version of eve::sqr which is equivalent to if_else (mask, sqr(x), x).

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft pf = {-1.0f, 2.0f, -3.0f, 182.0f};
    std::cout << "---- simd" << '\n'
    << "<- pf = " << pf << '\n'
    << "-> sqr[pf < 0](pf) = " << eve::sqr[pf < 0](pf) << '\n';
    return 0;
    }
  • eve::saturated

    The call eve::saturated(eve::sqr)(x) computes a saturated version of eve::sqr.

    Contrary to the non-decorated case, it guarantees that the result is elementwise greater or equal than 0. More specifically, for any signed integer value x, the expression:

    saturated(sqr)(x)

    evaluates to:

    `eve::valmax(as(x))` as soon as eve::saturated(eve::abs)(x) is greater than eve::sqrtvalmax(as(x)).

    Example