E.V.E  0.1-beta

◆ sqr

eve::sqr = {}
inlineconstexpr

Callable object computing the sqr operation.

Required header: #include <eve/function/sqr.hpp>

Members Functions

Member Effect
operator() the sqr operation
operator[] Construct a conditional version of current function object

template< value T > auto operator()( T x ) const noexcept;

Parameters

x: value.

Return value

Computes elementwise the square of x.

Warning
For real integral signed values if saturated(abs)(x) is greater than [eve::Sqrtvalmax(as(x))](eve::sqrtvalmax) the corresponding element result is undefined .

auto operator[]( conditional_expression auto cond ) const noexcept;

Higher-order function generating a masked version of eve::sqr

Parameters

cond : conditional expression

Return value

A Callable object so that the expression sqr[cond](x, ...) is equivalent to if_else(cond,sqr(x, ...),x)


Supported decorators

  • saturated

    Required header: #include <eve/function/saturated/sqr.hpp>

    The expression saturated(abs)(x) computes a saturated square of x. Contrary to the non-decorated case, this 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 saturated(abs)(x) is greater than `eve::Sqrtvalmax(as(x))`.

  • eve::diff, eve::diff_1st, eve::diff_nth

    Required header: #include <eve/function/diff/sqr.hpp>

    The expression diff(sqr)(x) computes the derivative of the function at x.

Example

See it live on Compiler Explorer

#include <eve/function/sqr.hpp>
#include <eve/function/saturated/sqr.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 callable_sqr_ sqr
Callable object computing the sqr operation.
Definition: sqr.hpp:95
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
constexpr saturated_type const saturated
Higher-order Callable Object imbuing saturation semantic onto other Callable Objects.
Definition: saturated.hpp:68
Wrapper for SIMD registers.
Definition: wide.hpp:65