E.V.E
v2023.02.15
 
Loading...
Searching...
No Matches

◆ average

auto eve::average = functor<average_t>
inlineconstexpr

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, 1.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, -eve::smallestposval(eve::as(1.0)), eve::smallestposval(eve::as(1.0))};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "-> average(wf0, wf1) = " << eve::average(wf0, wf1) << "\n";
std::cout << "-> average(wi0, wi1) = " << eve::average(wi0, wi1) << "\n";
std::cout << "-> average[ignore_last(2)](wi0, wi1) = " << eve::average[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> average[wi0 != 0](wi0, wi1) = " << eve::average[wi0 != 0](wi0, wi1) << "\n";
std::cout << "-> average[raw](wi0, wi1) = " << eve::average[eve::raw](wi0, wi1) << "\n";
std::cout << "-> average[upper](wi0, wi1) = " << eve::average[eve::upper](wi0, wi1) << "\n";
std::cout << "-> average[lower](wi0, wi1) = " << eve::average[eve::lower](wi0, wi1) << "\n";
std::cout << std::setprecision(20) << "-> average[upper](wf0, wf1) = " << eve::average[eve::upper](wf0, wf1) << "\n";
std::cout << "-> average[lower](wf0, wf1) = " << eve::average[eve::lower](wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> average[lower][strict](wf0, wf1) = " << eve::average[eve::lower][eve::strict](wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> average[upper][strict](wf0, wf1) = " << eve::average[eve::upper][eve::strict](wf0, wf1) << "\n";
}
constexpr auto average
tuple_callable computing the arithmetic mean of its arguments.
Definition average.hpp:120
constexpr auto smallestposval
Computes the smallest normal positive value.
Definition smallestposval.hpp:70
Lightweight type-wrapper.
Definition as.hpp:29
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:332
Wrapper for SIMD registers.
Definition wide.hpp:70

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto average(eve::integral_value auto x, eve::integral_value auto y) noexcept; // 1
constexpr auto average(eve::floating_value auto x, eve::floating_value auto ... xs) noexcept; // 2
constexpr auto average(kumi::non_empty_product_type auto const& tup) noexcept; // 3
// Lanes masking
constexpr auto average[conditional_expr auto c](/* any of the above overloads */) noexcept; // 4
constexpr auto average[logical_value auto m](/* any of the above overloads */) noexcept; // 4
// Semantic options
constexpr auto average[raw] (/* any of the above overloads */) noexcept; // 5
constexpr auto average[upper](eve::value auto x, eve::value auto y) noexcept; // 6
constexpr auto average[lower](eve::value auto x, eve::value auto y) noexcept; // 7
constexpr auto average[upper][strict](eve::value auto x, eve::value auto y) noexcept; // 6
constexpr auto average[lower][strict](eve::value auto x, eve::value auto y) noexcept; // 7
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:116
The concept integral_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:51
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:132
The concept value<T> is satisfied if and only if T satisfies either eve::scalar_value or eve::simd_va...
Definition value.hpp:34
EVE Main Namespace.
Definition abi.hpp:18

Parameters

Return value

The value of the arithmetic mean of the arguments is returned.

  1. For two integral parameters half the sum of x and y. No overflow occurs. If the sum is odd, the result is a rounded value at a distance guaranteed to be less than or equal to 0.5 of the average floating value, but may differ by unity from the truncation given by (x+y)/2. Moreover, as some architectures provide simd intrinsics to perform the operation, the scalar results may differ by one unit from simd ones which are system dependent.

    However the dowward (respectively upward) options can be used to ensure the result is equivalent to the integral conversion of floor((x+y)/2), (respectively ceil((x+y)/2)).

  2. the arithmetic mean of its arguments. No overflow occurs.
  3. the arithmetic mean of the tuple arguments. No overflow occurs.
  4. The operation is performed conditionnaly
  5. No provision is made to avoid overflows for more than 2 parameters.
  6. The average is computed in a 'round toward \(-\infty\) mode. The result is guaranted to be less or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality. For integral type entries, these are similar to ceil((x+y)/2), but converted to an integral value.
  7. The average is computed in a 'round toward \( +\infty\) mode. The result is guaranted to be greater or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.