E.V.E
v2023.02.15

◆ sign

eve::sign = {}
inlineconstexpr

Computes the sign of the parameter.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
T sign(T x) noexcept;
}
constexpr callable_sign_ sign
Computes the sign of the parameter.
Definition: sign.hpp:67
Definition: abi.hpp:18

Parameters

Return value

The elementwise sign of x computed as:

  • +1 , if x is greater than 0
  • -1 , if x is less than 0
  • 0 , if x is equal to 0
  • -0., if x is equal -0

If called on Nan, the result is the actual sign of Nan.

Example

#include <eve/module/core.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_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;sign[mask](x) provides a masked version of eve::sign which is equivalent to if_else (mask, sign(x), x).

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft pf = {-0.0f, 1.0f, -3.0f, -32768.0f,
    0.0f, -1.0f, 3.0f, 32768.0f};
    std::cout << "---- simd" << '\n'
    << "<- pf = " << pf << '\n'
    << "-> sign[abs(pf) < 2](pf) = " << eve::sign[eve::abs(pf) < 2](pf) << '\n';
    return 0;
    }
    constexpr callable_abs_ abs
    Computes the absolute value of the parameter.
    Definition: abs.hpp:107