E.V.E
v2022.09.01

◆ abs

eve::abs = {}
inlineconstexpr

Computes the absolute value of the parameter.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
T abs(T x) noexcept; //1
template< eve::floating_value T >
T abs(eve::as_complex<T> z) noexcept; //2
}
constexpr callable_abs_ abs
Computes the absolute value of the parameter.
Definition: abs.hpp:107
Definition: all_of.hpp:22

Parameters

Return value

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

    More specifically, for signed integers : the absolute value of eve::valmin is not representable and the result is undefined.

  2. modulus of the complex argument, i.e eve::hypot(eve::real(z), eve::imag(z))
Warning
abs is also a standard library function name and there possibly exists a C macro version which may be called instead of the EVE version. To avoid confusion, use the eve::abs notation.

Example

Real version

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft pf = {-1.0f, 2.0f, -3.0f, -32768.0f};
wide_it pi = {-1, 2, -3, -32768};
std::cout << "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "-> abs(pf) = " << eve::abs(pf) << '\n'
<< "<- pi = " << pi << '\n'
<< "-> saturated(abs)(pi) = " << eve::saturated(eve::abs)(pi) << '\n'
<< "-> abs(pi) = " << eve::abs(pi) << '\n';
float xf = -32768.0f;
std::int16_t xi = -32768;
std::cout << "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "-> abs(xf) = " << eve::abs(xf) << '\n'
<< "<- xi = " << xi << '\n'
<< "-> saturated(abs)(xi) = " << eve::saturated(eve::abs)(xi) << '\n'
<< "-> abs(xi) = " << eve::abs(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

Complex version

#include <eve/module/complex.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
wide_ft ref = { 0.0f, 1.0f, -1.0f, 0.5f};
wide_ft imf = { 2.0f , -1.0, -5.0, 0.0};
auto z = eve::as_complex_t<wide_ft>(ref, imf);
std::cout
<< "---- simd" << std::endl
<< "<- z = " << z << std::endl
<< "-> abs(z) = " << eve::abs(z) << std::endl;
return 0;
}

Semantic Modifiers

  • Masked Call

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

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_it pi = {-1, 2, -3, -18};
    std::cout << "---- simd" << '\n'
    << "<- pi = " << pi << '\n'
    << "-> abs[pi > -2](pi) = " << eve::abs[pi > -2](pi) << '\n';
    return 0;
    }
  • eve::saturated

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

    More specifically, for any signed integer value x, the expression eve::saturated(eve::abs)(eve::valmin(as(x))) evaluates to eve::valmax(as(x)).

    Example

    #include <eve/module/core.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_it pi = {-1, 2, -3, -32768};
    std::cout << "---- simd" << '\n'
    << "<- pi = " << pi << '\n'
    << "-> saturated(abs)(pi) = " << eve::saturated(eve::abs)(pi) << '\n';
    return 0;
    }
  • eve::pedantic

    The call eve::pedantic(eve::abs)(z) computes a pedantic version of the modulus.

    More specifically, pedantic(eve::hypot) is used in place of eve::hypot) for complex inputs

    Example

    #include <eve/module/complex.hpp>
    #include <eve/wide.hpp>
    #include <iostream>
    int main()
    {
    wide_ft ref = { 0.0f, 1.0f, -1.0f, eve::inf(eve::as(1.0f))};
    wide_ft imf = { 2.0f , -1.0f, -5.0f, eve::nan(eve::as(1.0f))};
    auto z = eve::as_complex_t<wide_ft>(ref, imf);
    std::cout
    << "---- simd" << std::endl
    << "<- z = " << z << std::endl
    << "-> pedantic(abs)(z) = " << eve::pedantic(eve::abs)(z) << std::endl;
    return 0;
    }
    constexpr callable_nan_ nan
    Computes the IEEE NaN constant.
    Definition: nan.hpp:53
    constexpr callable_inf_ inf
    Computes the infinity ieee value.
    Definition: inf.hpp:58
    constexpr pedantic_type const pedantic
    Higher-order Callable Object imbuing more standard semantic onto other Callable Objects.
    Definition: pedantic.hpp:56
    Lightweight type-wrapper.
    Definition: as.hpp:29