E.V.E
v2022.09.01

◆ 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:72
Definition: all_of.hpp:22

Parameters

Return value

  • Computes elementwise the sign of x.
  • For real x, the call 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

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

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