E.V.E  0.1-beta

◆ abs

eve::abs = {}
inlineconstexpr

Callable object computing the absolute value.

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

Members Functions

Member Effect
operator() Computes the absolute value of its parameter
operator[] Construct a conditional version of current function object

auto operator()(eve::value auto const& x ) const noexcept;
Definition: value.hpp:31

Parameters

x: An instance of eve::value

Return value

A value with the same type as x 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.

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 this, use the eve::abs notation.

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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::saturated

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

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

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

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

    The expression eve::diff( eve::abs )(x) computes the derivative of the function at x.

Example

See it live on Compiler Explorer

#include <eve/function/abs.hpp>
#include <eve/function/saturated/abs.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 callable_abs_ abs
Callable object computing the absolute value.
Definition: abs.hpp:91
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