E.V.E  0.1-beta

◆ sign

eve::sign = {}
inlineconstexpr

Callable object computing the sign operation.

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

Members Functions

Member Effect
operator() the sign 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 sign of x.

For real value x is semantically equivalent to:

  • If x is greater than 0, 1 is returned.
  • If x is less than 0, -1 is returned.
  • If x is zero, x is returned.

Moreover for floating real value if x is Nan, the result is Nan


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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

Example

See it live on Compiler Explorer

#include <eve/function/sign.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft pf = {-0.0f, 2.0f, -3.0f, -32768.0f,
0.0f, -2.0f, 3.0f, 32768.0f};
wide_it pi = { 0, 2, -3, -32768};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> sign(pf) = " << eve::sign(pf) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> sign(pi) = " << eve::sign(pi) << '\n';
float xf = -327.68f;
std::int16_t xi = -328;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> sign(xf) = " << eve::sign(xf) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> sign(xi) = " << eve::sign(xi) << '\n';
return 0;
}
constexpr callable_sign_ sign
Callable object computing the sign operation.
Definition: sign.hpp:84
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
Wrapper for SIMD registers.
Definition: wide.hpp:65