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

Detailed Description

Variables

constexpr auto eve::abs = functor<abs_t>
 elementwise_callable object computing the absolute value of the parameter.
constexpr auto eve::absmax = functor<absmax_t>
 tuple_callable computing the absolute value of the maximal element.
constexpr auto eve::absmin = functor<absmin_t>
 tuple_callable computing the absolute value of the minimal element.
constexpr auto eve::add = functor<add_t>
 tuple_callable computing the sum of its arguments.
constexpr auto eve::agm = functor<agm_t>
 elementwise_callable object computing the arithmetic-geometric mean.
constexpr auto eve::average = functor<average_t>
 tuple_callable computing the arithmetic mean of its arguments.
constexpr auto eve::ceil = functor<ceil_t>
 strict_elementwise_callable object computing the smallest integer not less than the input.
constexpr auto eve::chi = functor<chi_t>
 callable indicatrix of the interval \([lo, hi[\) or of the set for which the invocable returns true.
constexpr auto eve::clamp = functor<clamp_t>
 elementwise_callable clamping the value between two bounds.
constexpr auto eve::copysign = functor<copysign_t>
 elementwise_callable object computing the composition of a value with the magnitude of the first parameter and the bit of sign of the second one.
constexpr auto eve::cosine_similarity = functor<cosine_similarity_t>
 elementwise_callable object computing the elementwise cosine_similarity of the vector of the first half parameters by the vector of the last half.
constexpr auto eve::covariance = functor<covariance_t>
 elementwise_callable object computing the elementwise covariance product of the vector of the first half parameters by the vector of the last half.
constexpr auto eve::cumfun = functor<cumfun_t>
 callable converting a pack of values into a tuple of the cumulative application of a two parameter eve function defining an abelian monoid.
constexpr auto eve::cumprod = functor<cumprod_t>
 callable converting a pack of values into a tuple of the cumulative product of its values.
constexpr auto eve::cumsum = functor<cumsum_t>
 callable converting a pack of values into a tuple of the cumulative sum of its values.
constexpr auto eve::cumtrapz = functor<cumtrapz_t>
 callable converting a pack of values into a tuple of the cumulative trapezoidal of its values.
constexpr auto eve::dec = functor<dec_t>
 elementwise_callable object returning the input decremented by 1.
constexpr auto eve::diff = functor<diff_t>
 tuple_callable computing the nth adjacent differences of its arguments.
constexpr auto eve::dist = functor<dist_t>
 elementwise_callable object computing the distance of its arguments.
constexpr auto eve::div = functor<div_t>
 elementwise_callable object computing the division of multiple values.
constexpr auto eve::dot = functor<dot_t>
 elementwise_callable object computing the elementwise dot product of the vector of the first half parameter by thevector of the last half.
constexpr auto eve::fdim = functor<fdim_t>
 elementwise_callable computing the positive difference between the two parameters.
constexpr auto eve::floor = functor<floor_t>
 elementwise_callable object computing the largest integer not greater than the input.
constexpr auto eve::fmod = functor<fmod_t>
 elementwise_callable object mimicking the std::fmod function for floating values.
constexpr auto eve::frac = functor<frac_t>
 elementwise_callable computing the fractional part of the input.
constexpr auto eve::fracscale = functor<fracscale_t>
 strict_elementwise_callable object computing the reduced part of the scaled input.
constexpr auto eve::heaviside = functor<heaviside_t>
 elementwise_callable that return 1 if the input is greater than a threshold else 0.
constexpr auto eve::inc = functor<inc_t>
 elementwise_callable object returning the input incremented by 1.
constexpr auto eve::lerp = functor<lerp_t>
 Computes the linear interpolation.
constexpr auto eve::manhattan = functor<manhattan_t>
 tuple_callable object computing the manhattan norm ( \(l_1\)) of its arguments.
constexpr auto eve::max = functor<max_t>
 Computes the maximum of its arguments.
constexpr auto eve::maxabs = functor<maxabs_t>
 Computes the maximum of the absolute value norm ( \(l_\infty\)) of its arguments.
constexpr auto eve::maxmag = functor<maxmag_t>
 Computes the value for which the maximum of the absolute value of its arguments is obtained.
constexpr auto eve::min = functor<min_t>
 Computes the minimum of its arguments.
constexpr auto eve::minabs = functor<minabs_t>
 Computes the minimum of the absolute value of its arguments.
constexpr auto eve::minmag = functor<minmag_t>
 Computes the value for which the minimum of the absolute value of its arguments is obtained.
constexpr auto eve::minmax = functor<minmax_t>
 Computes the minimum and maximum of its arguments.
constexpr auto eve::minus = functor<minus_t>
 Computes the opposite of the parameter that must be signed.
constexpr auto eve::modf = functor<modf_t>
 elementwise_callable object computing the elementwise pair of fractional and integral parts of the value,
constexpr auto eve::mul = functor<mul_t>
 tuple_callable computing the product of its arguments.
constexpr auto eve::nearest = functor<nearest_t>
 strict_elementwise_callable object computing the nearest integer to the input.
constexpr auto eve::negabsmax = functor<negabsmax_t>
 tuple_callable computing the negated absolute value of the maximal element.
constexpr auto eve::negabsmin = functor<negabsmin_t>
 tuple_callable computing the negated absolute value of the minimal element.
constexpr auto eve::negate = functor<negate_t>
 elementwise_callable object computing the product of the first parameter by the sign of the second.
constexpr auto eve::negatenz = functor<negatenz_t>
 elementwise_callable object computing the product of the first parameter by the never zero sign of the second.
constexpr auto eve::negmaxabs = functor<negmaxabs_t>
 tuple_callable object computing the negated value of the element of maximal absolute value.
constexpr auto eve::negminabs = functor<negminabs_t>
 tuple_callable computing the negated value of the element of minimal absolute value.
constexpr auto eve::oneminus = functor<oneminus_t>
 elementwise_callable computing the value of one minus the input.
constexpr auto eve::rat = functor<rat_t>
 elementwise_callable object computing a rational approximation.
constexpr auto eve::rec = functor<rec_t>
 Computes the inverse of the parameter.
constexpr auto eve::reldist = functor<reldist_t>
 elementwise_callable object computing the relative distance of its arguments.
constexpr auto eve::rem = functor<rem_t>
 elementwise_callable object computing the remainder after division.
constexpr auto eve::remainder = functor<remainder_t>
 mimic the std::remainder function for floating values.
constexpr auto eve::round = functor<round_t>
 Computes the integer nearest to the input.
constexpr auto eve::roundscale = functor<roundscale_t>
 strict_elementwise_callable object computing the scaled input rounding.
constexpr auto eve::rsqrt = functor<rsqrt_t>
 Computes the inverse of the square root of the parameter.
constexpr auto eve::saturate = functor<saturate_t>
 strict_elementwise_callable computing the saturation of a value in a type.
constexpr auto eve::sign = functor<sign_t>
 elementwise_callable object computing the sign of the parameter.
constexpr auto eve::sign_alternate = functor<sign_alternate_t>
 Computes \((-1)^n\).
constexpr auto eve::signnz = functor<signnz_t>
 elementwise_callable object computing the never zero sign of the parameter.
constexpr auto eve::sqr = functor<sqr_t>
 Computes the square of the parameter.
constexpr auto eve::sqrt = functor<sqrt_t>
 Computes the elementwise square root of the parameter.
constexpr auto eve::sub = functor<sub_t>
 tuple_callable computing the difference of its first argument with the sum of the others.
constexpr auto eve::sum_of_squares = functor<sum_of_squares_t>
 tuple_callable object computing the sum of the squared values of its arguments.
constexpr auto eve::trapz = functor<trapz_t>
 tuple_callable object applying the trapezoidal composite rule to its arguments.
constexpr auto eve::trunc = functor<trunc_t>
 elementwise_callable object computing the integral part of x with the same sign as x.
constexpr auto eve::unfold = functor<unfold_t>
 tuple_callable utility to convert a pack of values into a tuple of scalar values.
constexpr auto eve::variance = functor<variance_t>
 tuple_callable computing the variance of its arguments.
constexpr auto eve::welford_average = functor<welford_average_t>
 tuple_callable computing the arithmetic mean of its arguments with the Welford algorithm, along with the number of elements involved.
constexpr auto eve::welford_covariance = functor<welford_covariance_t>
 elementwise_callable object computing the elementwise welford_covariance product of the vector of the first half parameter by thevector of the last half.
constexpr auto eve::welford_variance = functor<welford_variance_t>
 tuple_callable computing the variance of its arguments with the Welford algorithm, along with their average, second centered moment and count.
constexpr auto eve::neville = functor<neville_t>
 callable computing the value of the interpolation polynomial \(p\) of degree n, satisfying: \(p(x_i) = y_i\) for \(i = 0..n\)

Variable Documentation

◆ abs

auto eve::abs = functor<abs_t>
inlineconstexpr

elementwise_callable object computing the absolute value of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto abs(value auto x) noexcept; // 1
// Lanes masking
constexpr auto abs[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto abs[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto abs[saturated](value auto x) noexcept; // 3
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
The concept value<T> is satisfied if and only if T satisfies either eve::scalar_value or eve::simd_va...
Definition value.hpp:34
constexpr auto abs
elementwise_callable object computing the absolute value of the parameter.
Definition abs.hpp:86
constexpr auto saturated
Keeps the result inside the range of its type instead of wrapping or overflowing.
Definition core.hpp:104
EVE Main Namespace.
Definition abi.hpp:19

Parameters

Return value

  1. The absolute value of x if it is representable.
  2. The operation is performed conditionally.
  3. The saturated absolute value of x. More specifically, for signed integral, abs[saturated](valmin(as<T>{})) returns eve::valmax(as<T>{}))
Note
The absolute value of x is always representable except for The minimum value of integral signed values. In that case, contrarily to the standard, the result is not undefined behaviour, but just incorrect. In this case, eve::abs(valmin) returns valmin.
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.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> abs(wf0) = " << eve::abs(wf0) << "\n";
std::cout << "-> abs[ignore_last(2)](wf0) = " << eve::abs[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> abs[wf0 != 0](wf0) = " << eve::abs[wf0 != 0](wf0) << "\n";
std::cout << "-> abs(wu0) = " << eve::abs(wu0) << "\n";
std::cout << "-> abs[ignore_last(2)](wu0) = " << eve::abs[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> abs[wu0 != 0](wu0) = " << eve::abs[wu0 != 0](wu0) << "\n";
std::cout << "-> abs[saturated](wu0) = " << eve::abs[eve::saturated](wu0) << "\n";
std::cout << "-> abs(wi0) = " << eve::abs(wi0) << "\n";
std::cout << "-> abs[ignore_last(2)](wi0) = " << eve::abs[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> abs[wi0 != 0](wi0) = " << eve::abs[wi0 != 0](wi0) << "\n";
std::cout << "-> abs[saturated](wi0) = " << eve::abs[eve::saturated](wi0) << "\n";
}
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:361
Wrapper for SIMD registers.
Definition wide.hpp:94

◆ absmax

auto eve::absmax = functor<absmax_t>
inlineconstexpr

tuple_callable computing the absolute value of the maximal element.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto absmax(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto absmax(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto absmax[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto absmax[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic option
constexpr auto absmax[saturated](/* any of the above overloads */) noexcept; // 4
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto absmax[pedantic](/* any of the above overloads */) noexcept; // 5.1
constexpr auto absmax[numeric ](/* any of the above overloads */) noexcept; // 5.2
}
constexpr auto absmax
tuple_callable computing the absolute value of the maximal element.
Definition absmax.hpp:92
constexpr auto numeric
Makes NaN lose against any definite value.
Definition core.hpp:89
constexpr auto pedantic
Follows the corner cases of the corresponding standard function.
Definition core.hpp:91

Parameters

Return value

The absolute value of the maximal element is returned.

  1. If any element of the inputs is a NaN the corresponding output element is system-dependent
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. computation internally uses abs[saturated] instead of abs
  5. with numeric (resp. pedantic) max[numeric] (5.1) (resp. max[pedantic] (5.2)) is used internally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> absmax(wf0, wf1) = " << eve::absmax(wf0, wf1) << "\n";
std::cout << "-> absmax[ignore_last(2)](wf0, wf1) = " << eve::absmax[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> absmax[wf0 != 0](wf0, wf1) = " << eve::absmax[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> absmax[pedantic](wf0, wf1) = " << eve::absmax[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> absmax[numeric ](wf0, wf1) = " << eve::absmax[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> absmax(wu0, wu1) = " << eve::absmax(wu0, wu1) << "\n";
std::cout << "-> absmax(wi0, wi1) = " << eve::absmax(wi0, wi1) << "\n";
}

◆ absmin

auto eve::absmin = functor<absmin_t>
inlineconstexpr

tuple_callable computing the absolute value of the minimal element.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto absmin(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto absmin(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto absmin[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto absmin[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic options
constexpr auto absmin[saturated](/* any of the above overloads */) noexcept; // 4
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto absmin[pedantic](/* any of the above overloads */) noexcept; // 5.1
constexpr auto absmin[numeric ](/* any of the above overloads */) noexcept; // 5.2
}
constexpr auto absmin
tuple_callable computing the absolute value of the minimal element.
Definition absmin.hpp:94

Parameters

Return value

The absolute value of the minimal element is returned.

  1. If any element of the inputs is a NaN the corresponding output element is system-dependent
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. computation internally uses abs[saturated] instead of abs
  5. with numeric (resp. pedantic) min[numeric] (5.1) (resp. min[pedantic] (5.2)) is used internally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> absmin(wf0, wf1) = " << eve::absmin(wf0, wf1) << "\n";
std::cout << "-> absmin[ignore_last(2)](wf0, wf1) = " << eve::absmin[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> absmin[wf0 != 0](wf0, wf1) = " << eve::absmin[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> absmin[pedantic](wf0, wf1) = " << eve::absmin[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> absmin[numeric ](wf0, wf1) = " << eve::absmin[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> absmin(wu0, wu1) = " << eve::absmin(wu0, wu1) << "\n";
std::cout << "-> absmin(wi0, wi1) = " << eve::absmin(wi0, wi1) << "\n";
}

◆ add

auto eve::add = functor<add_t>
inlineconstexpr

tuple_callable computing the sum of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto add(value auto x, value auto ... xs) noexcept; // 1
constexpr auto add(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto add[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto add[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto add[saturated](/*any of the above overloads*/) noexcept; // 4
constexpr auto add[lower](/*any of the above overloads*/) noexcept; // 5
constexpr auto add[upper](/*any of the above overloads*/) noexcept; // 6
constexpr auto add[lower][strict](/*any of the above overloads*/) noexcept; // 5
constexpr auto add[upper][strict](/*any of the above overloads*/) noexcept; // 6
constexpr auto add[widen](/*any of the above overloads*/) noexcept; // 7
constexpr auto add[to_nearest_odd](/*any of the above overloads*/) noexcept; // 8
constexpr auto add[mod = p](/*any of the above overloads*/) noexcept; // 9
constexpr auto add[kahan](/*any of the above overloads*/) noexcept; // 10
}
constexpr auto add
tuple_callable computing the sum of its arguments.
Definition add.hpp:126
constexpr auto strict
Turns the guarantee of lower or upper into a strict inequality.
Definition core.hpp:105
constexpr auto widen
Computes the result in the upgraded element type.
Definition core.hpp:106
constexpr auto lower
Guarantees a result no greater than the exact mathematical one.
Definition core.hpp:103
constexpr auto upper
Guarantees a result no smaller than the exact mathematical one.
Definition core.hpp:102
constexpr auto to_nearest_odd
Rounds to the nearest integer, ties going to the odd one.
Definition core.hpp:109

Parameters

Return value

The value of the sum of the arguments is returned.

  1. Take care that for floating entries, the addition is not perfectly associative due to rounding errors. This call performs additions in reverse incoming order. If you have not changed the processor rounding mode, round toward nearest mode tie to even is generally performed on standard systems.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. The call add[saturated](...) computes a saturated version of add. Take care that for signed integral entries this kind of addition is not associative at all. This call perform saturated additions in reverse incoming order.
  5. The summation is computed in a round toward \(-\infty\) mode. The result is guaranteed to be less or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  6. The summation is computed in a round toward \(\infty\) mode. The result is guaranteed to be greater or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  7. The summation is computed in the double sized element type (if available). This decorator has no effect on double and 64 bits integrals.
  8. The summation is computed in a round toward nearest mode but tie to odd (not hardware available on common systems).
  9. compute the result in modular arithmetic. the parameters must be floating positive and less than the modulus. The modulus itself must be less than maxflint.
  10. A kahan like summation is performed ensuring better accuracy, using two-add function. If the x, ...xs parameter are assumed positive and non increasing (or at least with non increasing exponents) adding raw option can speed a bit the accurate summation,
Note
  • Although the infix notation with + is supported for two parameters, the + operator on standard scalar types is the original one and so can lead to automatic promotion.
  • add has many options. The regular user will only be interested with saturated, unless it has to deal with uncommon accuracy or order properties requirements whose enforcement can have an heavy cost even if hardware fma-like processor intrinsics are available.

External references

{kahan summation](https://en.wikipedia.org/wiki/Kahan_summation_algorithm)

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
#include <cfenv>
int main()
{
eve::wide wf0{1.0f, 1.0f, 2.0f, 3.0f, -1.0f, -2.0f, -3.0f, -4.0f};
eve::wide wf1{eve::eps(eve::as(1.0f))/4, -eve::eps(eve::as(1.0f))/4, 1.0f, -1.0f, 2.0f, -2.0f, 3.0f, -3.0f};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide<std::uint16_t, eve::fixed<8>> wu0{65534u, 65000u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide<std::uint16_t, eve::fixed<8>> wu1{2u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << std::setprecision(16) << "<- wf0 = " << wf0 << "\n";
std::cout << std::setprecision(16) << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> add(wf0, wf1) = " << eve::add(wf0, wf1) << "\n";
std::cout << "-> add[ignore_last(2)](wf0, wf1) = " << eve::add[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> add[wf0 != 0](wf0, wf1) = " << eve::add[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> add(wu0, wu1) = " << eve::add(wu0, wu1) << "\n";
std::cout << "-> add(wi0, wi1) = " << eve::add(wi0, wi1) << "\n";
std::cout << std::setprecision(16) << "-> add(wf0, wf1) = " << eve::add(wf0, wf1) << "\n";
std::cout << std::setprecision(16) << "-> add[to_nearest_odd(wf0, wf1) = " << eve::add(wf0, wf1) << "\n";
std::cout << std::setprecision(16) << "-> add[lower](wf0, wf1) = " << eve::add[eve::lower](wf0, wf1) << "\n";
std::cout << std::setprecision(16) << "-> add[upper](wf0, wf1) = " << eve::add[eve::upper](wf0, wf1) << "\n";
std::cout << std::setprecision(16) << "-> add[lower][strict](wf0, wf1) = " << eve::add[eve::lower][eve::strict](wf0, wf1) << "\n";
std::cout << std::setprecision(16) << "-> add[upper][strict](wf0, wf1) = " << eve::add[eve::upper][eve::strict](wf0, wf1) << "\n";
std::cout << "-> add(wu0, wu1) = " << eve::add(wu0, wu1) << "\n";
std::cout << "-> add[widen](wu0, wu1) = " << eve::add[eve::widen](wu0, wu1) << "\n";
std::cout << "-> add(wf0, wf1) = " << eve::add(wf0, wf1) << "\n";
std::cout << "-> add[widen](wf0, wf1) = " << eve::add[eve::widen](wf0, wf1) << "\n";
auto eps_4 = eve::eps(eve::as<float>())/4;
std::cout << "-> add(1.0f, eps_4, eps_4, eps_4, eps_4) = " << eve::add(1.0f, eps_4, eps_4, eps_4, eps_4) << "\n";
std::cout << "-> add[kahan](1.0f, eps_4, eps_4, eps_4, eps_4) = " << eve::add[eve::kahan](1.0f, eps_4, eps_4, eps_4, eps_4) << "// float result\n";
std::cout << "-> add(1.0f, eps_4, eps_4, eps_4, eps_4) = " << eve::add(1.0f, eps_4, eps_4, eps_4, eps_4) << "\n";
std::cout << "-> add[widen](1.0f, eps_4, eps_4, eps_4, eps_4) = " << float(eve::add[eve::widen](1.0f, eps_4, eps_4, eps_4, eps_4)) << "// double result converted to float\n";
auto tup = kumi::tuple{1.0f, eps_4, eps_4, eps_4, eps_4};
std::cout << "-> add[kahan](tup) = " << eve::add[eve::kahan](tup) << "\n";
}
constexpr auto eps
Computes a constant to the machine epsilon.
Definition eps.hpp:74
Lightweight type-wrapper.
Definition as.hpp:29

◆ agm

auto eve::agm = functor<agm_t>
inlineconstexpr

elementwise_callable object computing the arithmetic-geometric mean.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto agm(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto agm[conditional_expr auto c][floating_value auto x, floating_value auto y) noexcept; // 2.1
constexpr auto agm[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2.2
}
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:116
constexpr auto agm
elementwise_callable object computing the arithmetic-geometric mean.
Definition agm.hpp:87

Parameters

Return value

  1. The value of the arithmetic-geometric mean is returned. No overflow can occur. The two parameters must share the same sign.
  2. The operation is performed conditionally.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> agm(wf0, wf1) = " << eve::agm(wf0, wf1) << "\n";
std::cout << "-> agm[ignore_last(2)](wf0, wf1) = " << eve::agm[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> agm[wf0 != 0](wf0, wf1) = " << eve::agm[wf0 != 0](wf0, wf1) << "\n";
}

◆ average

auto eve::average = functor<average_t>
inlineconstexpr

tuple_callable computing the arithmetic mean of its arguments.

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(eve::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
constexpr auto average[widen](/* any of the above overloads */) noexcept; // 8
constexpr auto average[kahan](/* any of the above overloads */) noexcept; // 9
}
The concept integral_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:51
constexpr auto average
tuple_callable computing the arithmetic mean of its arguments.
Definition average.hpp:131
constexpr auto raw
Performs the operation minimally, trading accuracy for speed.
Definition core.hpp:95

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 lower (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 conditionally
  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 guaranteed 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 guaranteed to be greater 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 floor((x+y)/2) but converted to an integral value.
  8. The average is computed in the double sized element type (if available).
  9. Compensated algorithm for better precision.
Note
unless raw option is used no spurious overflow can be obtained.
See also
welford_average for incremental or parallel average computations.

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 << std::setprecision(15);
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 << "-> 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 << "-> average[lower][strict](wf0, wf1) = " << eve::average[eve::lower][eve::strict](wf0, wf1) << "\n";
std::cout << "-> average[upper][strict](wf0, wf1) = " << eve::average[eve::upper][eve::strict](wf0, wf1) << "\n";
auto eps_2 = eve::eps(eve::as<float>())/2;
std::cout << "-> average(1.0f, eps_2, eps_2, eps_2) = " << eve::average(1.0f, eps_2, eps_2, eps_2) << "\n";
std::cout << "-> average[kahan](1.0f, eps_2, eps_2, eps_2) = " << eve::average[eve::kahan](1.0f, eps_2, eps_2, eps_2) << " // float computation\n";
std::cout << "-> average[raw](1.0f, eps_2, eps_2, eps_2) = " << eve::average[eve::raw](1.0f, eps_2, eps_2, eps_2) << "\n";
auto deps_2 = double(eps_2);
std::cout << "-> average(1.0, deps_2, deps_2, eps_2) = " << float(eve::average[eve::kahan](1.0, deps_2, deps_2, deps_2)) << " // double computation converted to float\n";
auto tup = kumi::tuple{1.0f, eps_2, eps_2, eps_2};
std::cout << "-> average[kahan](tup) = " << eve::average[eve::kahan](tup) << "\n";
}
constexpr auto smallestposval
Computes the smallest normal positive value.
Definition smallestposval.hpp:71

◆ ceil

auto eve::ceil = functor<ceil_t>
inlineconstexpr

strict_elementwise_callable object computing the smallest integer not less than the input.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto ceil(value auto x) noexcept; // 1
// Lanes masking
constexpr auto ceil[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto ceil[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto ceil[almost = tol](floating_value auto x) noexcept; // 3
constexpr auto ceil[almost](floating_value auto x) noexcept; // 4
}
constexpr auto ceil
strict_elementwise_callable object computing the smallest integer not less than the input.
Definition ceil.hpp:94
constexpr auto almost
Turns an equality or an ordering into its tolerant form.
Definition core.hpp:313

Parameters

Return value

  1. The smallest integer not less than x. The standard proposes 4 rounding modes namely: FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO. This function object implements the FE_UPWARD version.
  2. The operation is performed conditionally.
  3. almost allows a fuzzy interpretation of ceil associated to a scalar tolerance.
    • with an integral value tol: computes the ceil of the previous nth representable value in the x type.
    • with a floating value tol: computes the ceil with a tolerance tol using Hagerty's FL5 function.
  4. with no tolerance value, the call is equivalent to ceil[tolerance = 3*eps(as(x))(x)

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> ceil(wf0) = " << eve::ceil(wf0) << "\n";
std::cout << "-> ceil[ignore_last(2)](wf0) = " << eve::ceil[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> ceil[wf0 != 0](wf0) = " << eve::ceil[wf0 != 0](wf0) << "\n";
std::cout << "-> ceil[almost](wf0) = " << eve::ceil[eve::almost](wf0) << "\n";
std::cout << "-> ceil(wu0) = " << eve::ceil(wu0) << "\n";
std::cout << "-> ceil[ignore_last(2)](wu0) = " << eve::ceil[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> ceil[wu0 != 0](wu0) = " << eve::ceil[wu0 != 0](wu0) << "\n";
std::cout << "-> ceil(wi0) = " << eve::ceil(wi0) << "\n";
std::cout << "-> ceil[ignore_last(2)](wi0) = " << eve::ceil[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> ceil[wi0 != 0](wi0) = " << eve::ceil[wi0 != 0](wi0) << "\n";
}

◆ chi

auto eve::chi = functor<chi_t>
inlineconstexpr

callable indicatrix of the interval \([lo, hi[\) or of the set for which the invocable returns true.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto chi(value auto x, value auto lo, value auto hi) noexcept; // 1
constexpr auto chi(value auto x, auto belongs) noexcept; // 2
// Lanes masking
constexpr auto chi[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto chi[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto chi
callable indicatrix of the interval or of the set for which the invocable returns true.
Definition chi.hpp:90
constexpr auto lo
Computes the least significant half of each lane.
Definition lo.hpp:73
constexpr auto hi
elementwise_callable computing the most significant half of each lane.
Definition hi.hpp:71

Parameters

Return value

  1. Each element of the result contains:
    • 0, if x is less than lo. or if hi is strictly less than x.
    • 1 otherwise. 2 1 in the type of x if belongs(x) evaluate to true else 0.
  2. The operation is performed conditionally.
Note
If any lo is not less or equal to the corresponding hi the routine asserts.

External references

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
eve::wide x = {2.0, -3.0, 0.1, 4.0};
eve::wide lo = {3.0, -4.0, -10.0, 0.0};
eve::wide hi = {4.0, -1.0, 0.0, 5.0};
auto belongs = [](auto v) {return v > 3.0 || v == 2.0; };
std::cout << " <- x = " << x << '\n';
std::cout << " <- lo = " << lo << '\n';
std::cout << " <- hi = " << hi << '\n';
std::cout << " -> chi(x, belongs) = " << eve::chi(x, belongs) << '\n';
std::cout << " -> chi(x, lo, hi) = " << eve::chi(x, lo, hi) << '\n';
std::cout << " -> chi[x > -2](x, lo, hi) = " << eve::chi[x > -2](x, lo, hi) << '\n';
}

◆ clamp

auto eve::clamp = functor<clamp_t>
inlineconstexpr

elementwise_callable clamping the value between two bounds.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto clamp(value auto x, value auto lo, value auto hi) noexcept; // 1
// Lanes masking
constexpr auto clamp[conditional_expr auto c](value auto x,
value auto lo, value auto hi) noexcept; // 2
constexpr auto clamp[logical_value auto m](value auto x,
value auto lo, value auto hi) noexcept; // 2
}
constexpr auto clamp
elementwise_callable clamping the value between two bounds.
Definition clamp.hpp:86

Parameters

Return value

  1. Each element of the result contains:
    • lo, if x is less than lo.
    • hi, if hi is less than x.
    • otherwise x.
  2. The operation is performed conditionally.
Note
If some lo are not less or equal to the corresponding hi the routine asserts.

External references

Example

// revision 2 TODO investigate last result
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wi = {2, -3, 0, 4};
eve::wide mi = {3, -2, -10, 0};
eve::wide ma = {4, -1, 0, 5};
std::cout << "<- wi = " << wi << "\n";
std::cout << "<- mi = " << mi << "\n";
std::cout << "<- ma = " << ma << "\n";
std::cout << "-> clamp(wi, mi, ma) = " << eve::clamp(wi, mi, ma) << "\n";
std::cout << "-> clamp[ignore_last(2)](wi, mi, ma) = " << eve::clamp[eve::ignore_last(2)](wi, mi, ma) << "\n";
std::cout << "-> clamp[wi != -4.0f](wi, mi, ma) = " << eve::clamp[wi != -2.0f](wi, mi, ma) << "\n";
}

◆ copysign

auto eve::copysign = functor<copysign_t>
inlineconstexpr

elementwise_callable object computing the composition of a value with the magnitude of the first parameter and the bit of sign of the second one.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
// Regular overload
constexpr auto copysign(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto copysign[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto copysign[logical_floating_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
}
constexpr auto copysign
elementwise_callable object computing the composition of a value with the magnitude of the first para...
Definition copysign.hpp:75

Parameters

Return value

  1. The value of the elementwise composition of a value with the magnitude of x and the bit of sign of y is returned.
  2. The operation is performed conditionally.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> copysign(wf0, wf1) = " << eve::copysign(wf0, wf1) << "\n";
std::cout << "-> copysign[ignore_last(2)](wf0, wf1) = " << eve::copysign[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> copysign[wf0 != 0](wf0, wf1) = " << eve::copysign[wf0 != 0](wf0, wf1) << "\n";
}

◆ cosine_similarity

auto eve::cosine_similarity = functor<cosine_similarity_t>
inlineconstexpr

elementwise_callable object computing the elementwise cosine_similarity of the vector of the first half parameters by the vector of the last half.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto cosine_similarity(eve::non_empty_product_type xs, eve::non_empty_product_type ys) noexcept; // 1
// Semantic options
constexpr auto cosine_similarity[widen] (/*any of the above overloads*/) noexcept; // 2
}
constexpr auto cosine_similarity
elementwise_callable object computing the elementwise cosine_similarity of the vector of the first ha...
Definition cosine_similarity.hpp:80

Parameters

Return value

  1. cosine_similarity product. \(\frac{\sum_s (x_s*y_s)}{\sqrt{\sum_s (x_s^2)*\sum_s (y_s^2)}}\). It is the cosine of the angle between the two vectors. One or minus one means thaat the vectors are proportionnal, zero that they are orthogonal.
  2. Uses the upgraded type for computations and result
See also
welford_cosine_similarity for incremental or parallel cosine_similarity and averages computations.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include "../../vec3.hpp"
int main()
{
kumi::tuple wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
kumi::tuple wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -4.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> cosine_similarity(wf0, wf1) = " << eve::cosine_similarity(wf0, wf1) << "\n";
std::cout << "-> cosine_similarity(wf0, wf0) = " << eve::cosine_similarity(wf0, wf0) << "\n";
vec3<float> a(1.0, 2.0, 3.0);
vec3<float> b(-3.0, -4.0, -6.0);
std::cout << "a " << a << std::endl;
std::cout << "b " << b << std::endl;
std::cout << "eve::cosine_similarity(a, b) = "<< eve::cosine_similarity(a, b) << std::endl;
std::cout << "eve::cosine_similarity(a, a) = " << eve::cosine_similarity(a, a) << std::endl;
std::cout << "eve::cosine_similarity(b, a) = " << eve::cosine_similarity(b, a) << std::endl;
std::cout << "eve::cosine_similarity(b, b) = " << eve::cosine_similarity(b, b) << std::endl;
// simd cosine_similarity eve::wide<vec3<float>, eve::fixed<4>>;
auto wa = wv3_t(a, a, b, b);
auto wb = wv3_t(b, a, a, b);
std::cout << "wa " << wa << std::endl;
std::cout << "wb " << wb << std::endl;
std::cout << "eve::cosine_similarity[eve::widen](wa, wb) = "<< eve::cosine_similarity(wa, wb) << std::endl;
kumi::tuple x{4.0f, 3.0f, 2.0f, 1.0f};
kumi::tuple y{1.0f, 2.0f, 3.0f, 4.0f};
std::cout << eve::cosine_similarity(x, x) << std::endl;
std::cout << eve::cosine_similarity(x, y) << std::endl;
std::cout << eve::cosine_similarity(y, x) << std::endl;
auto wt1 = kumi::generate<11>([](auto p){return w_t([p](auto q){return float(p+q); }); });
auto wt2 = kumi::generate<11>([](auto p){return w_t([p](auto q){return p*p/float((q+1)); }); });
std::cout << wt1 << std::endl;
std::cout << wt2 << std::endl;
}
constexpr generate_t< N > generate
SIMD register cardinal type.
Definition cardinals.hpp:39

◆ covariance

auto eve::covariance = functor<covariance_t>
inlineconstexpr

elementwise_callable object computing the elementwise covariance product of the vector of the first half parameters by the vector of the last half.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto covariance(eve::non_empty_product_type xs, eve::non_empty_product_type ys) noexcept; // 1
// Semantic options
constexpr auto covariance[kahan] (/*any of the above overloads*/) noexcept; // 2
constexpr auto covariance[unbiased](/*any of the above overloads*/) noexcept; // 3
constexpr auto covariance[widen] (/*any of the above overloads*/) noexcept; // 4
}
constexpr auto covariance
elementwise_callable object computing the elementwise covariance product of the vector of the first h...
Definition covariance.hpp:87

Parameters

  • xs, ys : tuples of floating value arguments.

Return value

  1. covariance product. \(\frac1N\sum_s (x_s-\bar{x_s})*(y_s-\bar{y_s})\). where N is the number of x_s (minus 1 if unbiased option is used).
  2. Uses a compensated kahan-like algorithm to compute the result more accurately
  3. see 1.
  4. Uses the upgraded type for computations and result
See also
welford_covariance for incremental or parallel covariance and averages computations.

Example

// revision 0
#include <eve/module/core.hpp>
#include "../../vec3.hpp"
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
// scalar covariance vec3<float>
vec3<float> a(1.0, 2.0, 3.0);
vec3<float> b(-3.0, -4.0, -6.0);
std::cout << "a " << a << std::endl;
std::cout << "b " << b << std::endl;
std::cout << "eve::covariance[eve::unbiased](a, b) = "<< eve::covariance[eve::unbiased](a, b) << std::endl;
std::cout << "eve::covariance[eve::unbiased](a, a) = " << eve::covariance[eve::unbiased](a, a) << std::endl;
std::cout << "eve::covariance[eve::unbiased](b, a) = " << eve::covariance[eve::unbiased](b, a) << std::endl;
std::cout << "eve::covariance[eve::unbiased](b, b) = " << eve::covariance[eve::unbiased](b, b) << std::endl;
// simd covariance eve::wide<vec3<float>, eve::fixed<4>>;
auto wa = wv3_t(a, a, b, b);
auto wb = wv3_t(b, a, a, b);
std::cout << "eve::covariance[eve::widen][eve::unbiased](wa, wb) = "<< eve::covariance[eve::widen][eve::unbiased](wa, wb) << std::endl;
std::cout << "wa " << wa << std::endl;
std::cout << "wb " << wb << std::endl;
kumi::tuple x{4.0f, 3.0f, 2.0f, 1.0f};
kumi::tuple y{1.0f, 2.0f, 3.0f, 4.0f};
std::cout << eve::covariance[eve::unbiased](x, x) << std::endl;
std::cout << eve::covariance[eve::unbiased](x, y) << std::endl;
std::cout << eve::covariance[eve::unbiased](y, x) << std::endl;
}

◆ cumfun

auto eve::cumfun = functor<cumfun_t>
inlineconstexpr

callable converting a pack of values into a tuple of the cumulative application of a two parameter eve function defining an abelian monoid.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto cumfun(typename f, eve::value auto ... xs) noexcept; // 1
constexpr auto cumfun(typename f, non_empty_product_type tup) noexcept; // 2
// Semantic options
constexpr auto cumfun[widen](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto cumfun
callable converting a pack of values into a tuple of the cumulative application of a two parameter ev...
Definition cumfun.hpp:98

Parameters

  • f: invocable of two arguments.
  • x: value arguments.
  • xs...: values arguments.
  • tup: kumi tuple of values.

Return value

  1. return a kumi tuple of the values of the cumulated values of all xs converted to the element type of the common value of the xs using f.
  2. same as 1., using the tuple elements.
  3. same of 1. or 2., but the computation is made on upgraded elements.
Note
currently cumfun can be applied with f being one of these EVE fonctors : eve::add, eve::mul, eve::min, eve::max``eve::bit_and, eve::bit_or, eve::bit_xor that define abelian monoids and each possess a well defined neutral element.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <numeric>
int main()
{
kumi::tuple t{ 2.0f, 3.0f, 1.0f,10000.0f, 10.0f};
std::cout << "t " << t << std::endl;
std::cout << "eve::cumfun(add, t) " << eve::cumfun(eve::add, t) << std::endl;
std::cout << "eve::cumfun(add, 1.0, 2.0, 3.0, 10000.0) " << eve::cumfun(eve::add, 1.0, 2.0, 3.0, 10000.0) << std::endl;
std::cout << "eve::cumfun(add, t) " << eve::cumfun(eve::add, t) << std::endl;
std::cout << "eve::cumfun[eve::widen](add, t) " << eve::cumfun[eve::widen](eve::add, t) << std::endl;
std::cout << "eve::cumfun(mul, t) " << eve::cumfun(eve::mul, t) << std::endl;
std::cout << "eve::cumfun(min, t) " << eve::cumfun(eve::min, t) << std::endl;
std::array<std::int16_t, 4> a{1, 2, 3, 32767};
auto ta = std::bit_cast<kumi::result::fill_t<4, std::int16_t>>(a);
std::cout << "ta " << ta << std::endl;
std::cout << "eve::cumfun[eve::saturated](add, ta) " << eve::cumfun[eve::saturated](eve::add, ta) << std::endl;
std::cout << "eve::cumfun(add, ta) " << eve::cumfun(eve::add, ta) << std::endl;
std::cout << "eve::cumfun[eve::widen](add, ta) " << eve::cumfun[eve::widen](eve::add, ta) << std::endl;
using wf_t = eve::wide<float>;
auto e = wf_t([](auto i, auto){return eve::sqr(float(i)); });
kumi::tuple wt{wf_t(e), 2.0f, 30000.0f, 100000.0f};
std::cout << "wt " << wt << std::endl;
std::cout << "eve::cumfun(add, wt) " << eve::cumfun(eve::add, wt) << std::endl;
std::cout << "eve::cumfun(mul, wt) " << eve::cumfun(eve::mul, wt) << std::endl;
std::cout << "eve::cumfun(add, wt) " << eve::cumfun(eve::add, wt) << std::endl;
std::cout << "eve::cumfun(min, wt) " << eve::cumfun(eve::min, wt) << std::endl;
std::cout << "eve::cumfun(max, wt) " << eve::cumfun(eve::max, wt) << std::endl;
std::cout << "eve::cumfun(bit_and, wt) " << eve::cumfun(eve::bit_and, wt) << std::endl;
std::cout << "eve::cumfun(bit_or, wt) " << eve::cumfun(eve::bit_or, wt) << std::endl;
std::cout << "eve::cumfun(bit_xor, wt) " << eve::cumfun(eve::bit_xor, wt) << std::endl;
};
constexpr auto sqr
Computes the square of the parameter.
Definition sqr.hpp:98
constexpr auto min
Computes the minimum of its arguments.
Definition min.hpp:100
constexpr auto mul
tuple_callable computing the product of its arguments.
Definition mul.hpp:128
constexpr auto max
Computes the maximum of its arguments.
Definition max.hpp:97
constexpr auto bit_xor
bit_callable object computing the bitwise XOR of its arguments.
Definition bit_xor.hpp:86
constexpr auto bit_and
bit_callable object computing the bitwise AND of its arguments.
Definition bit_and.hpp:93
constexpr auto bit_or
bit_callable object computing the bitwise OR of its arguments.
Definition bit_or.hpp:88

◆ cumprod

auto eve::cumprod = functor<cumprod_t>
inlineconstexpr

callable converting a pack of values into a tuple of the cumulative product of its values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto cumprod(eve::value auto ... xs) noexcept; // 1
constexpr auto cumprod(non_empty_product_type tup) noexcept; // 2
// Semantic options
constexpr auto cumprod[widen](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto cumprod
callable converting a pack of values into a tuple of the cumulative product of its values.
Definition cumprod.hpp:89

Parameters

  • x: value arguments.
  • xs...: values arguments.
  • tup: kumi tuple of values.

Return value

  1. return a kumi tuple of the values of the cumulated products of all xs converted to the element type of the common value of the xs.
  2. same as 1., using the tuple elements.
  3. same of 1. or 2., but the computation is made on upgraded elements.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <bit>
int main()
{
kumi::tuple t{1.0f, 2.0f, 3.0f, 10000.0f};
std::cout << "t " << t << std::endl;
std::cout << "eve::cumprod(t) " << eve::cumprod(t) << std::endl;
std::cout << "eve::cumprod(1.0, 2.0, 3.0, 10000.0) " << eve::cumprod(1.0, 2.0, 3.0, 10000.0) << std::endl;
std::cout << "eve::cumprod(t) " << eve::cumprod(t) << std::endl;
std::cout << "eve::cumprod[eve::widen](t) " << eve::cumprod[eve::widen](t) << std::endl;
std::array<std::int16_t, 4> a{1, 2, 3, 10000};
auto ta = std::bit_cast<kumi::result::fill_t<4, std::int16_t>>(a);
std::cout << "eve::cumprod[eve::saturated](ta) " << eve::cumprod[eve::saturated](ta) << std::endl;
std::cout << "eve::cumprod(ta) " << eve::cumprod(ta) << std::endl;
std::cout << "eve::cumprod[eve::widen](ta) " << eve::cumprod[eve::widen](ta) << std::endl;
using wf_t = eve::wide<float>;
auto e = wf_t([](auto i, auto){return eve::sqr(float(i)); });
kumi::tuple wt{wf_t(e), 2.0f, 30000.0f, 10000.0f};
std::cout << "wt " << wt << std::endl;
std::cout << "eve::cumprod(wt) " << eve::cumprod(wt) << std::endl;
};

◆ cumsum

auto eve::cumsum = functor<cumsum_t>
inlineconstexpr

callable converting a pack of values into a tuple of the cumulative sum of its values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto cumsum(eve::value auto ... xs) noexcept; // 1
constexpr auto cumsum(non_empty_product_type tup) noexcept; // 2
// Semantic options
constexpr auto cumsum[widen](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto cumsum
callable converting a pack of values into a tuple of the cumulative sum of its values.
Definition cumsum.hpp:90

Parameters

  • x: value arguments.
  • xs...: values arguments.
  • tup: kumi tuple of values.

Return value

  1. return a kumi tuple of the values of the cumulated sums of all xs converted to the element type of the common value of the xs.
  2. same as 1., using the tuple elements.
  3. same of 1. or 2., but the computation is made on upgraded elements.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <numeric>
int main()
{
kumi::tuple t{1.0, 2.0, 3.0, 10.0, 20.0, 30.0, 100.0, 200.0, 300.0, };
std::cout << "t " << t << std::endl;
std::cout << "eve::cumsum(t) " << eve::cumsum(t) << std::endl;
std::cout << "eve::cumsum(1.0, 2.0, 3.0, 10000.0) " << eve::cumsum(1.0, 2.0, 3.0, 10000.0) << std::endl;
std::cout << "eve::cumsum(t) " << eve::cumsum(t) << std::endl;
std::cout << "eve::cumsum[eve::widen](t) " << eve::cumsum[eve::widen](t) << std::endl;
std::array<std::int16_t, 4> a{1, 2, 3, 10000};
auto ta = std::bit_cast<kumi::result::fill_t<4, std::int16_t>>(a);
std::cout << "ta " << ta << std::endl;
std::cout << "eve::cumsum[eve::saturated](ta) " << eve::cumsum[eve::saturated](ta) << std::endl;
std::cout << "eve::cumsum(ta) " << eve::cumsum(ta) << std::endl;
std::cout << "eve::cumsum[eve::widen](ta) " << eve::cumsum[eve::widen](ta) << std::endl;
using wf_t = eve::wide<float>;
auto e = wf_t([](auto i, auto){return eve::sqr(float(i)); });
kumi::tuple wt{wf_t(e), 2.0f, 30000.0f, 10000.0f};
std::cout << "wt " << wt << std::endl;
std::cout << "eve::cumsum(wt) " << eve::cumsum(wt) << std::endl;
};

◆ cumtrapz

auto eve::cumtrapz = functor<cumtrapz_t>
inlineconstexpr

callable converting a pack of values into a tuple of the cumulative trapezoidal of its values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto trapz(eve::non_empty_product_type auto const& x,
eve::non_empty_product_type auto const& y) noexcept; // 1
constexpr auto trapz(floating_value auto ... ys) noexcept; // 2
constexpr auto trapz(eve::non_empty_product_type auto const& y) noexcept; // 2
constexpr auto trapz(floating_value h,
eve::non_empty_product_type auto const& y) noexcept; // 2
constexpr auto trapz(eve::invocable f, floating_value auto ... xs) noexcept; // 4
constexpr auto trapz(eve::invocable f, eve::non_empty_product_type auto const& x) noexcept; // 4
// Semantic options
constexpr auto trapz[widen](/*any of the above overloads*/) noexcept; // 4
}
constexpr auto trapz
tuple_callable object applying the trapezoidal composite rule to its arguments.
Definition trapz.hpp:120

Parameters

Return value

  1. return a kumi tuple of the values of the cumulated trapz of all xs converted to the element type of the common value of the xs. the xs have to be sorted in ascending order.
  2. same as 1., using the tuple elements.
  3. same of 1. or 2., but upgrading the elements of the result.
Note
Where [trapz}(eve::trapz) returns only the overall integral, cumtrapz returns a tuple of the current partialintegral values.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
kumi::tuple t{1.0, 2.0, 3.0, 4.0, 5.0};
std::cout << "t " << t << std::endl;
std::cout << "eve::cumtrapz(t) " << eve::cumtrapz(t) << std::endl;
std::cout << "eve::cumtrapz(1.0, 2.0, 3.0, 4.0, 5.0) " << eve::cumtrapz(1.0, 2.0, 3.0, 4.0, 5.0) << std::endl;
std::cout << "eve::cumtrapz(t) " << eve::cumtrapz(t) << std::endl;
std::cout << "eve::cumtrapz(0.5, t) " << eve::cumtrapz(0.5, t) << std::endl;
std::cout << "eve::cumtrapz(t, t) " << eve::cumtrapz(t, t) << std::endl;
std::cout << "eve::cumtrapz(t, kumi::map(eve::sqr, t)) " << eve::cumtrapz(t, kumi::map(eve::sqr, t)) << std::endl;
std::cout << "eve::cumtrapz(eve::sqr, t) " << eve::cumtrapz(eve::sqr, t) << std::endl;
using wf_t = eve::wide<double>;
auto e = wf_t([](auto i, auto){return eve::sqr(float(i)); });
kumi::tuple wt{wf_t(e), 12.0f, 13.0f, 100.0f};
std::cout << "wt " << wt << std::endl;
std::cout << "eve::cumtrapz(wt) " << eve::cumtrapz(wt) << std::endl;
};
constexpr auto cumtrapz
callable converting a pack of values into a tuple of the cumulative trapezoidal of its values.
Definition cumtrapz.hpp:137
constexpr map_t map

◆ dec

auto eve::dec = functor<dec_t>
inlineconstexpr

elementwise_callable object returning the input decremented by 1.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto dec(value auto x) noexcept; // 1
// Lanes masking
constexpr auto dec[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto dec[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto dec[saturated](value auto x) noexcept; // 3
constexpr auto dec[lower](value auto x) noexcept; // 4
constexpr auto dec[upper](value auto x) noexcept; // 5
constexpr auto dec[lower][strict](value auto x) noexcept; // 4
constexpr auto dec[upper][strict](value auto x) noexcept; // 5
constexpr auto dec[mod = p](value auto x) noexcept; // 6
constexpr auto dec
elementwise_callable object returning the input decremented by 1.
Definition dec.hpp:109

Parameters

Return value

  1. The value of x - 1 is returned.
  2. The operation is performed conditionally.
  3. The saturated decrementation of x. More specifically, for signed integral, dec[saturated](valmin(as<T>{})) returns eve::valmin(as<T>{})). This has no effect on floating types.
  4. The decrement is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality. This has no effect on integral types.
  5. The decrement is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater or equal to the exact one (except for Nans).Combined with strict the option ensures generally faster computation, but strict inequality. This has no effect on integral types.
  6. Computes the result in modular arithmetic. the parameter must be flint positive and less than the modulus. The modulus itself must be positive and less than maxflint. The result of the operation is unspecified if these conditions are not met.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
auto sml = eve::smallestposval(eve::as(1.0));
eve::wide wf0{sml, -sml, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wf1{0.0, 34.0, 0.0, 72.0, 4.0, 3.0, 2.0, 1.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> dec(wf0) = " << eve::dec(wf0) << "\n";
std::cout << "-> dec[ignore_last(2)](wf0) = " << eve::dec[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> dec[wf0 != 0](wf0) = " << eve::dec[wf0 != 0](wf0) << "\n";
std::cout << "-> dec(wu0) = " << eve::dec(wu0) << "\n";
std::cout << "-> dec[ignore_last(2)](wu0) = " << eve::dec[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> dec[wu0 != 0](wu0) = " << eve::dec[wu0 != 0](wu0) << "\n";
std::cout << "-> dec[saturated](wu0) = " << eve::dec[eve::saturated](wu0) << "\n";
std::cout << "-> dec(wi0) = " << eve::dec(wi0) << "\n";
std::cout << "-> dec[ignore_last(2)](wi0) = " << eve::dec[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> dec[wi0 != 0](wi0) = " << eve::dec[wi0 != 0](wi0) << "\n";
std::cout << "-> dec[saturated](wi0) = " << eve::dec[eve::saturated](wi0) << "\n";
std::cout << std::setprecision(20) << "-> dec[lower](wf0) = " << eve::dec[eve::lower](wf0) << "\n";
std::cout << std::setprecision(20) << "-> dec[upper](wf0) = " << eve::dec[eve::upper](wf0) << "\n";
std::cout << std::setprecision(20) << "-> dec[lower][strict](wf0) = " << eve::dec[eve::lower][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> dec[upper][strict](wf0) = " << eve::dec[eve::upper][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> dec[mod = 97](wf1) = " << eve::dec[eve::mod = 97](wf1) << "\n";
}

◆ diff

auto eve::diff = functor<diff_t>
inlineconstexpr

tuple_callable computing the nth adjacent differences of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto diff(eve::floating_value auto const& xs...) noexcept; // 1
constexpr auto diff(eve::non_empty_product_type auto const& x) noexcept; // 1
typename<auto N> constexpr auto diff(kumi::index_t<N>, eve::floating_value auto const& xs...) noexcept; // 2
typename<auto N> constexpr auto diff(kumi::index_t<N>,eve::non_empty_product_type auto const& x) noexcept; // 2
}
constexpr auto diff
tuple_callable computing the nth adjacent differences of its arguments.
Definition diff.hpp:97

Parameters

Return value

  • 1. Return a tuple containing the elementwise adjacent differences of the parameters or of the elements of the tuple.
  • 2. Return a tuple containing the elementwise Nth adjacent differences of the parameters or of the elements of the tuple.

External references

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::hexfloat << std::endl;
{
kumi::tuple tt{1.5000e-5, 2.2500, 3.3750, 5.0625, 7.0, 11.0, 17.0, 25.0};
std::cout << " < - tt = " << tt << std::endl;
std::cout << " -> diff(index_t<0>, tt) = " << eve::diff(kumi::index_t<0>{}, tt) << std::endl;
std::cout << " -> diff(tt) = " << eve::diff(tt) << std::endl;
std::cout << " -> diff(index_t<1>, tt) = " << eve::diff(kumi::index_t<1>{}, tt) << std::endl;
std::cout << " -> diff(index_t<2>, tt) = " << eve::diff(kumi::index_t<2>{}, tt) << std::endl;
std::cout << " -> diff(index_t<7>, tt) = " << eve::diff(kumi::index_t<7>{}, tt) << std::endl;
std::cout << " -> diff(index_t<8>, tt) = " << eve::diff(kumi::index_t<8>{}, tt) << std::endl;
std::cout << "float" << 8*sizeof(kumi::get<0>(eve::diff(kumi::index_t<1>{}, tt))) << std::endl;
}
{
kumi::tuple tt{1.5000e-5f, 2.2500f, 3.3750f, 5.0625f, 7.0f, 11.0f, 17.0f, 25.0f};
std::cout << " < - tt = " << tt << std::endl;
std::cout << " -> diff(index_t<0>, tt) = " << eve::diff(kumi::index_t<0>{}, tt) << std::endl;
std::cout << " -> diff(tt) = " << eve::diff(tt) << std::endl;
std::cout << " -> diff(index_t<1>, tt) = " << eve::diff(kumi::index_t<1>{}, tt) << std::endl;
std::cout << " -> diff(index_t<2>, tt) = " << eve::diff(kumi::index_t<2>{}, tt) << std::endl;
std::cout << " -> diff(index_t<7>, tt) = " << eve::diff(kumi::index_t<7>{}, tt) << std::endl;
std::cout << " -> diff(index_t<8>, tt) = " << eve::diff(kumi::index_t<8>{}, tt) << std::endl;
std::cout << "float" << 8*sizeof(kumi::get<0>(eve::diff(kumi::index_t<1>{}, tt))) << std::endl;
}
using eve::widen;
{
kumi::tuple tt{1.5000e-5f, 2.2500f, 3.3750f, 5.0625f, 7.0f, 11.0f, 17.0f, 25.0f};
std::cout << " < - tt = " << tt << std::endl;
std::cout << " -> diff[widen](index_t<0>, tt) = " << eve::diff[widen](kumi::index_t<0>{}, tt) << std::endl;
std::cout << " -> diff[widen](tt) = " << eve::diff[widen](tt) << std::endl;
std::cout << " -> diff[widen](index_t<1>, tt) = " << eve::diff[widen](kumi::index_t<1>{}, tt) << std::endl;
std::cout << " -> diff[widen](index_t<2>, tt) = " << eve::diff[widen](kumi::index_t<2>{}, tt) << std::endl;
std::cout << " -> diff[widen](index_t<7>, tt) = " << eve::diff[widen](kumi::index_t<7>{}, tt) << std::endl;
std::cout << " -> diff[widen](index_t<8>, tt) = " << eve::diff[widen](kumi::index_t<8>{}, tt) << std::endl;
std::cout << "float" << 8*sizeof(kumi::get<0>(eve::diff[widen](kumi::index_t<1>{}, tt))) << std::endl;
}
{
std::cout << " -> diff( ...) = " << eve::diff(1.5000e-5f, 2.2500f, 3.3750f, 5.0625f, 7.0f, 11.0f, 17.0f, 25.0f) << std::endl;
std::cout << " -> diff(index_t<1>, ...) = " << eve::diff(kumi::index_t<1>{}, 1.5000e-5f, 2.2500f, 3.3750f, 5.0625f, 7.0f, 11.0f, 17.0f, 25.0f) << std::endl;
std::cout << " -> diff[widen]( ...) = " << eve::diff[widen](1.5000e-5f, 2.2500f, 3.3750f, 5.0625f, 7.0f, 11.0f, 17.0f, 25.0f) << std::endl;
std::cout << " -> diff[widen](index_t<1>, ...) = " << eve::diff[widen](kumi::index_t<1>{}, 1.5000e-5f, 2.2500f, 3.3750f, 5.0625f, 7.0f, 11.0f, 17.0f, 25.0f) << std::endl;
}
}
decltype(auto) constexpr get(record< Ts... > &r) noexcept

◆ dist

auto eve::dist = functor<dist_t>
inlineconstexpr

elementwise_callable object computing the distance of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto dist(eve::value auto x, eve::value auto y) noexcept; // 1
// Lanes masking
constexpr auto dist[conditional_expr auto c](eve::value auto x, eve::value auto y) noexcept; // 2
constexpr auto dist[logical_value auto m](eve::value auto x, eve::value auto y) noexcept; // 2
// Semantic options
constexpr auto dist[saturated](eve::value auto x, eve::value auto y) noexcept; // 3
constexpr auto dist[pedantic](eve::value auto x, eve::value auto y) noexcept; // 4
}
constexpr auto dist
elementwise_callable object computing the distance of its arguments.
Definition dist.hpp:86

Parameters

Return value

  1. The value of the distance of the arguments is returned, i.e. abs (x-y).
  2. The operation is performed conditionally.
  3. The call dist[saturated](x, y) computes a saturated distance. Contrary to the non decorated case, it guarantees that the result is always defined. If \(|x-y|\) is not representable, the greatest representable positive value is returned.
  4. dist[pedantic](x, y)computes a distance which is NaN if and only if one of the parameters is a NaN.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> dist(wf0, wf1) = " << eve::dist(wf0, wf1) << "\n";
std::cout << "-> dist[ignore_last(2)](wf0, wf1) = " << eve::dist[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> dist[wf0 != 0](wf0, wf1) = " << eve::dist[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> dist[pedantic](wf0, wf1) = " << eve::dist[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> dist(wu0, wu1) = " << eve::dist(wu0, wu1) << "\n";
std::cout << "-> dist[ignore_last(2)](wu0, wu1) = " << eve::dist[eve::ignore_last(2)](wu0, wu1) << "\n";
std::cout << "-> dist[wu0 != 0](wu0, wu1) = " << eve::dist[wu0 != 0](wu0, wu1) << "\n";
std::cout << "-> dist[saturated](wu0, wu1) = " << eve::dist[eve::saturated](wu0, wu1) << "\n";
std::cout << "-> dist[pedantic](wu0, wu1) = " << eve::dist[eve::pedantic](wu0, wu1) << "\n";
std::cout << "-> dist(wi0, wi1) = " << eve::dist(wi0, wi1) << "\n";
std::cout << "-> dist[ignore_last(2)](wi0, wi1) = " << eve::dist[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> dist[wi0 != 0](wi0, wi1) = " << eve::dist[wi0 != 0](wi0, wi1) << "\n";
std::cout << "-> dist[saturated](wi0, wi1) = " << eve::dist[eve::saturated](wi0, wi1) << "\n";
std::cout << "-> dist[pedantic](wi0, wi1) = " << eve::dist[eve::pedantic](wi0, wi1) << "\n";
}

◆ div

auto eve::div = functor<div_t>
inlineconstexpr

elementwise_callable object computing the division of multiple values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto div(value auto x, value auto ... xs) noexcept; // 1
constexpr auto div(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto div[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto div[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic exclusive options
constexpr auto div[upward](/*any of the above overloads*/) noexcept; // 4
constexpr auto div[downward](/*any of the above overloads*/) noexcept; // 4
constexpr auto div[toward_zero](/*any of the above overloads*/) noexcept; // 4
constexpr auto div[to_nearest](/*any of the above overloads*/) noexcept; // 4
constexpr auto div[lower](/*any of the above overloads*/) noexcept; // 5
constexpr auto div[upper](/*any of the above overloads*/) noexcept; // 6
constexpr auto div[lower][srict](/*any of the above overloads*/) noexcept; // 5
constexpr auto div[upper][srict](/*any of the above overloads*/) noexcept; // 6
// Semantic options
constexpr auto div[right](/*any of the above overloads*/) noexcept; // 1
constexpr auto div[saturated](integral_value auto x, integral_value auto y)) noexcept; // 7
constexpr auto div[left](/*any of the above overloads*/) noexcept; // 8
constexpr auto div[mod = p](/*any of the above overloads*/) noexcept; // 9
}
constexpr auto div
elementwise_callable object computing the division of multiple values.
Definition div.hpp:147
constexpr auto downward
Rounds toward .
Definition core.hpp:80
constexpr auto to_nearest
Rounds to the nearest integer, ties going to the even one.
Definition core.hpp:99
constexpr auto right
Applies the operation in the order the operands are written.
Definition core.hpp:96
constexpr auto toward_zero
Rounds toward zero.
Definition core.hpp:100
constexpr auto upward
Rounds toward .
Definition core.hpp:101
constexpr auto left
Swaps the two operands before applying the operation.
Definition core.hpp:87

Parameters

Return value

  1. If the arguments are \((x_i)_{0\le i\le n}\) The value of \(x/\prod_1^n x_i\) is returned.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. If z denotes the prduct of the xs, the call div[o](x, xs...) produces:
  5. The floating division is computed in a rounding mode such that the result is guaranteed to be less or equal to the exact one (except for Nans).Combined with strict the option ensures generally faster computation, but strict inequality.
  6. The floating division is computed in a rounding mode such that the result is guaranteed to be greater or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  7. computes the saturated division of x by y. The result is always defined even if the denominator is 0.
  8. div[left](a, b) is semantically equivalent to div(b, a)

    The relevant cases are just in fact the division by 0 for integral types in which case the result is eve::valmin(as(x)) or [valmax(as(x))](ref eve::valmax) according to the dividend sign, and the division of valmin(as(x)) by -1 that produces valmax(as(x)).

  9. compute the result in modular arithmetic. the parameters must be positive flint and less than the modulus. The modulus itself must be less than maxflint.
Note
  • With two parameters, the call div(x, y) is equivalent to x / y if x or y is an simd value.
  • Although the infix notation with / is supported for two parameters, the / operator on standard scalar types is the original one and so can lead to automatic promotion.

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wf_t pf = {3.2, 1.6, 3, 32700}, qf = {4.1, 2.345, 1, 100};
std::cout << "---- simd" << std::setprecision(10) << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> div(pf, qf) = " << eve::div(pf, qf) << '\n'
<< " -> pf / qf = " << pf / qf << '\n'
<< " -> div[left](pf, qf) = " << eve::div[eve::left](pf, qf) << "\n"
<< " -> div[upper](pf, qf) = " << eve::div[eve::upper](pf, qf) << '\n'
<< " -> div[lower](pf, qf) = " << eve::div[eve::lower](pf, qf) << '\n'
<< " -> div[pf> qf](pf, qf) = " << eve::div[pf>qf](pf, qf) << '\n';
wf_t rf = {3034, 200, 333, 32700}, sf = {4, 7, 13, 100};
std::cout << "---- simd" << '\n'
<< " <- rf = " << rf << '\n'
<< " <- sf = " << sf << '\n'
<< " -> div[toward_zero](rf, sf) = " << eve::div[eve::toward_zero](rf, sf) << '\n'
<< " -> div[lower](rf, sf) = " << eve::div[eve::lower](rf, sf) << '\n'
<< " -> div[upper](rf, sf) = " << eve::div[eve::upper](rf, sf) << '\n'
<< " -> div[to_nearest](rf, sf) = " << eve::div[eve::to_nearest](rf, sf) << '\n';
auto k = kumi::tuple{pf, pf, pf, 1};
std::cout << "---- multi parameters" << '\n'
<< " -> div(k) = " << eve::div(k) << '\n'
<< " -> div(kumi::tuple{pf, pf}) = " << eve::div( kumi::tuple{pf, pf}) << '\n'
<< " -> div(kumi::tuple{pf, 1.0f) = " << eve::div( kumi::tuple{pf, 1.0f}) << '\n'
<< " -> div(kumi::tuple{1.0f, pf) = " << eve::div( kumi::tuple{1.0f, pf}) << '\n';
}

◆ dot

auto eve::dot = functor<dot_t>
inlineconstexpr

elementwise_callable object computing the elementwise dot product of the vector of the first half parameter by thevector of the last half.

Warning
This is not a reduction ! For reals the dot product is the product

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto dot(auto value... xs, auto value... ys) noexcept; // 1
constexpr auto dot(kumi::tuple xs, kumi::tuple ys) noexcept; // 2
// Semantic options
constexpr auto dot[widen](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto dot
elementwise_callable object computing the elementwise dot product of the vector of the first half par...
Definition dot.hpp:92

Parameters

Return value

  1. dot product. \(\sum_s x_s*y_s\).
  2. use the content of the tuples
  3. The summation is computed in the double sized element type (if available). This decorator has no effect on double and 64 bits integrals.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> dot(wf0, wf1) = " << eve::dot(wf0, wf1) << "\n";
std::cout << "-> dot(wu0, wu1) = " << eve::dot(wu0, wu1) << "\n";
std::cout << "-> dot(wi0, wi1) = " << eve::dot(wi0, wi1) << "\n";
std::cout << "-> dot(wf0, wf1, wf0, wf1) = "<< eve::dot(wf0, wf1, wf0, wf1) << "\n";
std::cout << "-> dot[kahan](wf0, wf1, wf0, wf1) = "<< eve::dot[eve::kahan](wf0, wf1, wf0, wf1) << "\n";
std::cout << "-> dot[widen](wf0, wf1, wf0, wf1) = "<< eve::dot[eve::widen](wf0, wf1, wf0, wf1) << "\n";
auto vwf0= kumi::tuple{wf0, 2*wf0, 3*wf0};
auto vwf1= kumi::tuple{wf1, 2*wf1, 3*wf1};
std::cout << "-> dot(vwf0, vwf1) = " << eve::dot(vwf0, vwf1) << "\n";
std::cout << "-> dot[widen](vwf0, vwf1) = " << eve::dot[eve::widen](vwf0, vwf1) << "\n";
std::cout << "-> dot[kahan](vwf0, vwf1) = " << eve::dot[eve::kahan](vwf0, vwf1) << "\n";
}

◆ fdim

auto eve::fdim = functor<fdim_t>
inlineconstexpr

elementwise_callable computing the positive difference between the two parameters.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto fdim(value auto x, value auto y) noexcept; // 1
// Lanes masking
constexpr auto fdim[conditional_expr auto c](value auto x, value auto y) noexcept; // 2
constexpr auto fdim[logical_value auto m](value auto x, value auto y) noexcept; // 2
}
constexpr auto fdim
elementwise_callable computing the positive difference between the two parameters.
Definition fdim.hpp:75

Parameters

Return value

  1. Returns the positive difference between x and y:
    • if x>y, x-y is returned,
    • if x<=y, +0 is returned,
    • otherwise a Nan is returned.
  2. The operation is performed conditionally

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> fdim(wf0, wf1) = " << eve::fdim(wf0, wf1) << "\n";
std::cout << "-> fdim[ignore_last(2)](wf0, wf1) = " << eve::fdim[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> fdim[wf0 != 0](wf0, wf1) = " << eve::fdim[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> fdim(wu0, wu1) = " << eve::fdim(wu0, wu1) << "\n";
std::cout << "-> fdim[ignore_last(2)](wu0, wu1) = " << eve::fdim[eve::ignore_last(2)](wu0, wu1) << "\n";
std::cout << "-> fdim[wu0 != 0](wu0, wu1) = " << eve::fdim[wu0 != 0](wu0, wu1) << "\n";
std::cout << "-> fdim(wi0, wi1) = " << eve::fdim(wi0, wi1) << "\n";
std::cout << "-> fdim[ignore_last(2)](wi0, wi1) = " << eve::fdim[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> fdim[wi0 != 0](wi0, wi1) = " << eve::fdim[wi0 != 0](wi0, wi1) << "\n";
}

◆ floor

auto eve::floor = functor<floor_t>
inlineconstexpr

elementwise_callable object computing the largest integer not greater than the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto floor(value auto x) noexcept; // 1
// Lanes masking
constexpr auto floor[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto floor[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto floor[almost = tol](floating_value auto x) noexcept; // 3
constexpr auto floor[almost](floating_value auto x) noexcept; // 4
}
constexpr auto floor
elementwise_callable object computing the largest integer not greater than the input.
Definition floor.hpp:94

Parameters

Return value

1. The largest integer not greater than `x`.
   The standard proposes 4 rounding modes namely: `FE_TONEAREST`, `FE_DOWNWARD`, `FE_UPWARD`,
   `FE_TOWARDZERO`. This function object implements the `FE_DOWNWARD` version.
2. [The operation is performed conditionally](@ref conditional).
3. `almost` allows a fuzzy interpretation of ceil associated to a scalar tolerance.
    - with an integral value `tol`: computes the floor of the next nth
      representable value in the `x` type.
    - with a floating  value `tol`: computes the floor with a tolerance `tol`
      using Hagerty's FL5 function.
4. with no tolerance value, the call is equivalent to `ceil[tolerance = 3*eps(as(x))(x)`

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> floor(wf0) = " << eve::floor(wf0) << "\n";
std::cout << "-> floor[ignore_last(2)](wf0) = " << eve::floor[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> floor[wf0 != 0](wf0) = " << eve::floor[wf0 != 0](wf0) << "\n";
std::cout << "-> floor[almost](wf0) = " << eve::floor[eve::almost](wf0) << "\n";
std::cout << "-> floor(wu0) = " << eve::floor(wu0) << "\n";
std::cout << "-> floor[ignore_last(2)](wu0) = " << eve::floor[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> floor[wu0 != 0](wu0) = " << eve::floor[wu0 != 0](wu0) << "\n";
std::cout << "-> floor(wi0) = " << eve::floor(wi0) << "\n";
std::cout << "-> floor[ignore_last(2)](wi0) = " << eve::floor[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> floor[wi0 != 0](wi0) = " << eve::floor[wi0 != 0](wi0) << "\n";
}

◆ fmod

auto eve::fmod = functor<fmod_t>
inlineconstexpr

elementwise_callable object mimicking the std::fmod function for floating values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto fmod(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto fmod[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto fmod[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
}
constexpr auto fmod
elementwise_callable object mimicking the std::fmod function for floating values.
Definition fmod.hpp:79

Parameters

Return value

  1. Returns the remainder after division of x by y and mimic the behaviour of std::fmod. In particular:
    • If x is \(\pm0\), \(\pm0\) is returned.
    • If x is \(\pm\inf\) or NaN, NaN is returned.
    • If y is \(\pm0\), NaN is returned.
    • If y is \(\pm\inf\) and x is finite, xis returned.
  2. The operation is performed conditionally.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> fmod(wf0, wf1) = " << eve::fmod(wf0, wf1) << "\n";
std::cout << "-> fmod[ignore_last(2)](wf0, wf1) = " << eve::fmod[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> fmod[wf0 != 0](wf0, wf1) = " << eve::fmod[wf0 != 0](wf0, wf1) << "\n";
}

◆ frac

auto eve::frac = functor<frac_t>
inlineconstexpr

elementwise_callable computing the fractional part of the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto frac(value auto x) noexcept; // 1
// Lanes masking
constexpr auto frac[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto frac[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto frac[raw](floating_value auto x) noexcept; // 3
constexpr auto frac[pedantic](floating_value auto x) noexcept // 4
constexpr auto frac[almost = tol](floating_value auto x) noexcept; // 5
constexpr auto frac[almost](floating_value auto x) noexcept; // 6
}
constexpr auto frac
elementwise_callable computing the fractional part of the input.
Definition frac.hpp:83

Parameters

Return value

  1. The fractional part of x with the same sign as x: x-trunc(x), but keeping the zero sign.
  2. The operation is performed conditionally.
  3. just x-trunc(x).
  4. zeros and not finite values are all handled properly.
  5. almost allows a fuzzy interpretation of frac using internally the almost version of trunc.
  6. with no tolerance value, the call is equivalent to frac[tolerance = 3*eps(as(x))(x)

External references

◆ fracscale

auto eve::fracscale = functor<fracscale_t>
inlineconstexpr

strict_elementwise_callable object computing the reduced part of the scaled input.

The call is equivalent to a0-roundscale(a0,scale)

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto fracscale(floating_value auto x, index_t<scale>) noexcept; // 1
constexpr auto fracscale(floating_value auto x, integral_value scale) noexcept; // 1
// Semantic option
constexpr auto fracscale[downward](/*any of the above overloads*/) noexcept; // 2
constexpr auto fracscale[upward](/*any of the above overloads*/) noexcept; // 2
constexpr auto fracscale[to_nearest](/*any of the above overloads*/) noexcept; // 2
constexpr auto fracscale[toward_zero](/*any of the above overloads*/) noexcept; // 2
}
constexpr auto fracscale
strict_elementwise_callable object computing the reduced part of the scaled input.
Definition fracscale.hpp:82

Parameters

  • x: real floating value.
  • scale : int or std::integral_constant of int type limited to the range [0, 15].

Return value

  1. Returns the elementwise reduced part of the scaled input. The number of fraction bits retained is specified by scale. By default the internal rounding after scaling is done to nearest integer. The call fracscale(x, scale) is equivalent to x-eve::ldexp(eve::nearest(eve::ldexp(x,scale), -scale))
  2. with o denoting one of these options the call is equivalent to x-eve::roundscale[o](x, scale)

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f);
wf0+= 1.2345678;
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> fracscale(wf0, index_t<0>()) = " << eve::fracscale(wf0, eve::index_t<0>()) << "\n";
std::cout << "-> fracscale(wf0, 2*wi) = " << eve::fracscale(wf0, wu0) << "\n";
std::cout << "-> fracscale[downward](wf0, index_t<0>()) = " << eve::fracscale[eve::downward](wf0, eve::index_t<0>()) << "\n";
std::cout << "-> fracscale[upward](wf0, index_t<0>()) = " << eve::fracscale[eve::upward](wf0, eve::index_t<0>()) << "\n";
std::cout << "-> fracscale[to_nearest](wf0, index_t<0>()) = " << eve::fracscale[eve::to_nearest](wf0, eve::index_t<0>()) << "\n";
std::cout << "-> fracscale[toward_zero](wf0, index_t<0>()) = " << eve::fracscale[eve::toward_zero](wf0, eve::index_t<0>()) << "\n";
}

◆ heaviside

auto eve::heaviside = functor<heaviside_t>
inlineconstexpr

elementwise_callable that return 1 if the input is greater than a threshold else 0.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto heaviside(value auto x) noexcept; // 1
constexpr auto heaviside(value auto x, auto s) noexcept; // 2
// Lanes masking
constexpr auto heaviside[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto heaviside[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto heaviside
elementwise_callable that return 1 if the input is greater than a threshold else 0.
Definition heaviside.hpp:92

Parameters

Return value

  1. Each element of the result contains:
    • 0, if x is less or equal to zero.
    • 1 otherwise.
  2. Each element of the result contains:
    • 0, if x is less or equal to s (default to zero).
    • 1 otherwise.
  3. The operation is performed conditionally.

External references

Example

#include <eve/module/core.hpp>
#include <eve/wide.hpp>
#include <iostream>
int main()
{
eve::wide x = {2.0, -3.0, 0.1, 4.0};
eve::wide s = {3.0, -4.0, -10.0, 0.0};
std::cout << " <- x = " << x << '\n';
std::cout << " <- s = " << s << '\n';
std::cout << " -> heaviside(x) = " << eve::heaviside(x) << '\n';
std::cout << " -> heaviside(x, s) = " << eve::heaviside(x, s) << '\n';
std::cout << " -> heaviside[x > -2](x) = " << eve::heaviside[x > -2](x, s) << '\n';
}

◆ inc

auto eve::inc = functor<inc_t>
inlineconstexpr

elementwise_callable object returning the input incremented by 1.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto inc(value auto x) noexcept; // 1
// Lanes masking
constexpr auto inc[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto inc[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto inc[saturated](value auto x) noexcept; // 3
constexpr auto inc[lower](value auto x) noexcept; // 4
constexpr auto inc[upper](value auto x) noexcept; // 5
constexpr auto inc[lower][strict](value auto x) noexcept; // 4
constexpr auto inc[upper][strict](value auto x) noexcept; // 5
constexpr auto inc[mod = p](value auto x) noexcept; // 6
}
constexpr auto inc
elementwise_callable object returning the input incremented by 1.
Definition inc.hpp:108

Parameters

Return value

  1. The value of x + 1 is returned.
  2. The operation is performed conditionally.
  3. The saturated incrementation of x. More specifically, for signed integral, inc[saturated](valmax(as<T>{})) returns eve::valmax(as<T>{})). This has no effect on floating types.
  4. The increment is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality. This has no effect on integral types.
  5. The increment is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality. This has no effect on integral types.
  6. Computes the result in modular arithmetic. The parameter must be flint positive and less than the modulus. The modulus itself must be positive and less than maxflint. The result of the operation is unspecified if these conditions are not met.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
auto sml = eve::smallestposval(eve::as(1.0));
eve::wide wf0{sml, -sml, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, 34.0, 0.0, 72.0, 4.0, 3.0, 2.0, 96.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> inc(wf0) = " << eve::inc(wf0) << "\n";
std::cout << "-> inc[ignore_last(2)](wf0) = " << eve::inc[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> inc[wf0 != 0](wf0) = " << eve::inc[wf0 != 0](wf0) << "\n";
std::cout << "-> inc(wu0) = " << eve::inc(wu0) << "\n";
std::cout << "-> inc[ignore_last(2)](wu0) = " << eve::inc[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> inc[wu0 != 0](wu0) = " << eve::inc[wu0 != 0](wu0) << "\n";
std::cout << "-> inc[saturated](wu0) = " << eve::inc[eve::saturated](wu0) << "\n";
std::cout << "-> inc(wi0) = " << eve::inc(wi0) << "\n";
std::cout << "-> inc[ignore_last(2)](wi0) = " << eve::inc[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> inc[wi0 != 0](wi0) = " << eve::inc[wi0 != 0](wi0) << "\n";
std::cout << "-> inc[saturated](wi0) = " << eve::inc[eve::saturated](wi0) << "\n";
std::cout << std::setprecision(20) << "-> inc[lower](wf0) = " << eve::inc[eve::lower](wf0) << "\n";
std::cout << std::setprecision(20) << "-> inc[upper](wf0) = " << eve::inc[eve::upper](wf0) << "\n";
std::cout << std::setprecision(20) << "-> inc[lower][strict](wf0) = " << eve::inc[eve::lower][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> inc[upper][strict](wf0) = " << eve::inc[eve::upper][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> inc[mod = 97](wf1) = " << eve::inc[eve::mod = 97](wf1) << "\n";
}

◆ lerp

auto eve::lerp = functor<lerp_t>
inlineconstexpr

Computes the linear interpolation.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto lerp(floating_value auto x, floating_value auto y, floating_value auto t) noexcept; // 1
// Lanes masking
constexpr auto lerp[conditional_expr auto c](floating_value auto x, floating_value auto y, floating_value auto t) noexcept; // 2
constexpr auto lerp[logical_value auto m](floating_value auto x, floating_value auto y, floating_value auto t) noexcept; // 2
// Semantic options
constexpr auto abs[pedantic](floating_value auto x, floating_value auto y, floating_value auto t) noexcept; // 3
}
constexpr auto lerp
Computes the linear interpolation.
Definition lerp.hpp:75

Parameters

Return value

  1. The value of the interpolation (or extrapolation) between x and y is returned. The call is semantically equivalent to x+t*(y-x) but uses fma opportunities.
  2. The operation is performed conditionally
  3. pedantic version of fma is used internally.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wf2{0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wf2 = " << wf2 << "\n";
std::cout << "-> lerp(wf0, wf1, wf2) = " << eve::lerp(wf0, wf1, wf2) << "\n";
std::cout << "-> lerp[ignore_last(2)](wf0, wf1, wf2) = " << eve::lerp[eve::ignore_last(2)](wf0, wf1, wf2) << "\n";
std::cout << "-> lerp[wf0 != 0](wf0, wf1, wf2) = " << eve::lerp[wf0 != 0](wf0, wf1, wf2) << "\n";
}

◆ manhattan

auto eve::manhattan = functor<manhattan_t>
inlineconstexpr

tuple_callable object computing the manhattan norm ( \(l_1\)) of its arguments.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0{0.01, 1.01, 2.01, 3.01, -1.01, -2.01, -3.01, -4.01};
eve::wide wf1{0.01, -4.01, 1.01, -1.01, 2.01, -2.01, 3.01, -3.01};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> manhattan(wf0, wf1) = " << eve::manhattan(wf0, wf1) << "\n";
std::cout << "-> manhattan[ignore_last(2)](wf0, wf1) = " << eve::manhattan[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> manhattan[wf0 != 0](wf0, wf1) = " << eve::manhattan[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> manhattan[pedantic](wf0, wf1) = " << eve::manhattan[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> manhattan(wu0, wu1) = " << eve::manhattan(wu0, wu1) << "\n";
std::cout << "-> manhattan(wi0, wi1) = " << eve::manhattan(wi0, wi1) << "\n";
std::cout << std::hexfloat;
std::cout << "-> manhattan[lower][strict](wf0, wf1) = " << eve::manhattan[eve::lower][eve::strict](wf0, wf1) << "\n";
std::cout << "-> manhattan[lower](wf0, wf1) = " << eve::manhattan[eve::lower](wf0, wf1) << "\n";
std::cout << "-> manhattan(wf0, wf1) = " << eve::manhattan(wf0, wf1) << "\n";
std::cout << "-> manhattan[upper](wf0, wf1) = " << eve::manhattan[eve::upper](wf0, wf1) << "\n";
std::cout << "-> manhattan[upper][strict](wf0, wf1) = " << eve::manhattan[eve::upper][eve::strict](wf0, wf1) << "\n";
auto eps_2 = eve::eps(eve::as<float>())/2;
auto tup = kumi::tuple{1.0f, eps_2, eps_2, eps_2};
std::cout << "-> manhattan[kahan](tup) = " << eve::manhattan[eve::kahan](tup) << "\n";
float o = 1.0f;
float i = eve::inf(eve::as(o));
float n = eve::nan(eve::as(o));
float m = (eve::valmax(eve::as(o))/3)*2;
std::cout << "<- o = " << o << "\n";
std::cout << "-> i = " << i << "\n";
std::cout << "-> n = " << n << "\n";
std::cout << "-> manhattan(i, o, -i) = " << eve::manhattan(i, o, -i) << "\n";
std::cout << "-> manhattan(i, o, n) = " << eve::manhattan(i, o, n) << "\n";
std::cout << "-> manhattan[pedantic](i, o, -i) = " << eve::manhattan[eve::pedantic](i, o, -i) << "\n";
std::cout << "-> manhattan[pedantic](i, o, n) = " << eve::manhattan[eve::pedantic](i, o, n) << "\n";
std::cout << "-> manhattan[pedantic](o, o, n) = " << eve::manhattan[eve::pedantic](o, o, n) << "\n";
std::cout << "-> manhattan[pedantic](o, n, o) = " << eve::manhattan[eve::pedantic](o, n, o) << "\n";
std::cout << "-> manhattan[pedantic](n, o, o) = " << eve::manhattan[eve::pedantic](n, o, o) << "\n";
std::cout << "-> manhattan (o, o, n) = " << eve::manhattan(o, o, n) << "\n";
std::cout << "-> manhattan (o, n, o) = " << eve::manhattan(o, n, o) << "\n";
std::cout << "-> manhattan (n, o, o) = " << eve::manhattan(n, o, o) << "\n";
std::cout << "-> manhattan(n, n, n) = " << eve::manhattan(n, n, n) << "\n";
std::cout << "-> manhattan(m, o, o) = " << eve::manhattan(m, o, o)<< "\n";
std::cout << "-> manhattan(m, m, n) = " << eve::manhattan(m, m, n)<< "\n";
std::cout << "-> manhattan(i, n) = " << eve::manhattan(i, n) << "\n";
std::cout << "-> manhattan[pedantic](m, m, n) = " << eve::manhattan[eve::pedantic](m, m, n)<< "\n";
std::cout << "-> manhattan[pedantic](i, n) = " << eve::manhattan[eve::pedantic](i, n) << "\n";
}
constexpr auto manhattan
tuple_callable object computing the manhattan norm ( ) of its arguments.
Definition manhattan.hpp:100
constexpr auto nan
Computes the IEEE quiet NaN constant.
Definition nan.hpp:67
constexpr auto valmax
Computes the greatest representable value.
Definition valmax.hpp:67
constexpr auto inf
Computes the infinity ieee value.
Definition inf.hpp:67

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto manhattan(value auto x, value auto ... xs) noexcept; // 1
constexpr auto manhattan(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto manhattan[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto manhattan[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto manhattan[saturated](/*any of the above overloads*/) noexcept; // 4
constexpr auto manhattan[pedantic](/*any of the above overloads*/) noexcept; // 5
constexpr auto manhattan[kahan](/*any of the above overloads*/) noexcept; // 6
}

Parameters

Return value

  1. The value of the sum of the absolute value of the arguments is returned.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. internally uses saturated options.
  5. returns \(\infty\) as soon as after disabling possible Nan parameters the result is \(\infty\).
  6. uses kahan like compensated algorithm for better accuracy.

External references

◆ max

auto eve::max = functor<max_t>
inlineconstexpr

Computes the maximum of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto max(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto max(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto max[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto max[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto max[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto max[numeric ](/* any of the above overloads */) noexcept; // 5
}

Parameters

Return value

  1. the maximal element is returned. If one of the elements is NaN the result is system dependent.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. Ensures conformity to the standard. That is for two parameters to be equivalent to: (x < y) ? y : x and this behaviour is also ensured on n parameters calls as if this scheme is recursively used.
  5. NaNs are considered less than anything else.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> max(wf0, wf1) = " << eve::max(wf0, wf1) << "\n";
std::cout << "-> max[ignore_last(2)](wf0, wf1) = " << eve::max[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> max[wf0 != 0](wf0, wf1) = " << eve::max[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> max[pedantic](wf0, wf1) = " << eve::max[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> max[pedantic](wf0, wf1) = " << eve::max[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> max[numeric ](wf0, wf1) = " << eve::max[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> max(wu0, wu1) = " << eve::max(wu0, wu1) << "\n";
std::cout << "-> max(wi0, wi1) = " << eve::max(wi0, wi1) << "\n";
std::cout << "-> max(0.,1.,2.,3.,-3.,-4.,-6.0) = " << eve::max(0.0, 1.0, 2.0, 3.0, -3.0, -4., -6.0) << "\n";
}

◆ maxabs

auto eve::maxabs = functor<maxabs_t>
inlineconstexpr

Computes the maximum of the absolute value norm ( \(l_\infty\)) of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto maxabs(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto maxabs(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto maxabs[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto maxabs[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto maxabs[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto maxabs[numeric ](/* any of the above overloads */) noexcept; // 5
constexpr auto maxabs[widen](/* any of the above overloads */) noexcept; // 6
constexpr auto maxabs[drastic](/* any of the above overloads */) noexcept; // 7
}
constexpr auto maxabs
Computes the maximum of the absolute value norm ( ) of its arguments.
Definition maxabs.hpp:95

Parameters

Return value

  1. the value of the maximum of the absolute values is returned. If one of the elements is NaN the result is system dependent.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. Ensures conformity to the standard. That is for two parameters to be equivalent to: (|x| < |y|) ? |y| : |x| and this behaviour is also ensured on n parameters calls as if this scheme was recursively used. If one of the arguments is \(\pm\infty\) returns \(\infty\) even if some other arguments are NaNs. (with no consideration of Nans)
  5. NaNs are considered less than anything else.
  6. compute the upgraded result if available.
  7. returns NaN as soon as one of the parameters is a NaN.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> maxabs(wf0, wf1) = " << eve::maxabs(wf0, wf1) << "\n";
std::cout << "-> maxabs[ignore_last(2)](wf0, wf1) = " << eve::maxabs[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> maxabs[wf0 != 0](wf0, wf1) = " << eve::maxabs[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> maxabs[pedantic](wf0, wf1) = " << eve::maxabs[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> maxabs[numeric ](wf0, wf1) = " << eve::maxabs[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> maxabs(wu0, wu1) = " << eve::maxabs(wu0, wu1) << "\n";
std::cout << "-> maxabs(wi0, wi1) = " << eve::maxabs(wi0, wi1) << "\n";
float o = 1.0f;
float i = eve::inf(eve::as(o));
float n = eve::nan(eve::as(o));
float m = (eve::valmax(eve::as(o))/3)*2;
std::cout << "<- o = " << o << "\n";
std::cout << "-> i = " << i << "\n";
std::cout << "-> n = " << n << "\n";
std::cout << "-> maxabs(i, o, -i) = " << eve::maxabs(i, o, -i) << "\n";
std::cout << "-> maxabs(i, o, n) = " << eve::maxabs(i, o, -i) << "\n";
std::cout << "-> maxabs[pedantic](o, o, n) = " << eve::maxabs[eve::pedantic](o, o, n) << "\n";
std::cout << "-> maxabs[pedantic](o, n, o) = " << eve::maxabs[eve::pedantic](o, n, o) << "\n";
std::cout << "-> maxabs[pedantic](n, o, o) = " << eve::maxabs[eve::pedantic](n, o, o) << "\n";
std::cout << "-> maxabs[numeric ](o, o, n) = " << eve::maxabs[eve::numeric ](o, o, n) << "\n";
std::cout << "-> maxabs[numeric](o, n, o) = " << eve::maxabs[eve::numeric](o, n, o) << "\n";
std::cout << "-> maxabs[numeric](n, o, o) = " << eve::maxabs[eve::numeric](n, o, o) << "\n";
std::cout << "-> maxabs (o, o, n) = " << eve::maxabs(o, o, n) << "\n";
std::cout << "-> maxabs (o, n, o) = " << eve::maxabs(o, n, o) << "\n";
std::cout << "-> maxabs (n, o, o) = " << eve::maxabs(n, o, o) << "\n";
std::cout << "-> maxabs(n, n, n) = " << eve::maxabs(n, n, n) << "\n";
std::cout << "-> maxabs(m, o, o) = " << eve::maxabs(m, o, o)<< "\n";
std::cout << "-> maxabs(i, o, n) = " << eve::maxabs(i, o, n)<< "\n";
std::cout << "-> maxabs[drastic](i, o, n) = " << eve::maxabs[eve::drastic](i, o, n)<< "\n";
std::cout << "-> maxabs(i, o, n) = " << eve::maxabs(i, o, n)<< "\n";
}

◆ maxmag

auto eve::maxmag = functor<maxmag_t>
inlineconstexpr

Computes the value for which the maximum of the absolute value of its arguments is obtained.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto maxmag(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto maxmag(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto maxmag[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto maxmag[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto maxmag[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto maxmag[numeric ](/* any of the above overloads */) noexcept; // 4
}
constexpr auto maxmag
Computes the value for which the maximum of the absolute value of its arguments is obtained.
Definition maxmag.hpp:90

Parameters

Return value

  1. The element of greatest absolute value is returned. For instance for two elements:
    • If |x| > |y|, x is returned.
    • If |x| < |y|, y is returned.
    • Otherwise max(x, y) is returned. For n parameters the result is computed as if this scheme was recursively used.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. The behaviour of eve::maxmag[o](x, y) (where o is one of these two options) is identical except that if |x| == |y|, max[o] is used.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> maxmag(wf0, wf1) = " << eve::maxmag(wf0, wf1) << "\n";
std::cout << "-> maxmag[ignore_last(2)](wf0, wf1) = " << eve::maxmag[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> maxmag[wf0 != 0](wf0, wf1) = " << eve::maxmag[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> maxmag[pedantic](wf0, wf1) = " << eve::maxmag[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> maxmag[numeric ](wf0, wf1) = " << eve::maxmag[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> maxmag(wu0, wu1) = " << eve::maxmag(wu0, wu1) << "\n";
std::cout << "-> maxmag(wi0, wi1) = " << eve::maxmag(wi0, wi1) << "\n";
}

◆ min

auto eve::min = functor<min_t>
inlineconstexpr

Computes the minimum of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto min(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto min(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto min[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto min[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto min[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto min[numeric ](/* any of the above overloads */) noexcept; // 5
}

Parameters

Return value

  1. the miniimal element is returned. If one of the elements is NaN the result is system dependent.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. Ensures conformity to the standard. That is for two parameters to be equivalent to: (x < y) ? x : y and this behaviour is also ensured on n parameters calls as if this scheme is recursively used.
  5. NaNs are considered greater than anything else.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> min(wf0, wf1) = " << eve::min(wf0, wf1) << "\n";
std::cout << "-> min[ignore_last(2)](wf0, wf1) = " << eve::min[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> min[wf0 != 0](wf0, wf1) = " << eve::min[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> min[pedantic](wf0, wf1) = " << eve::min[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> min[numeric ](wf0, wf1) = " << eve::min[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> min(wu0, wu1) = " << eve::min(wu0, wu1) << "\n";
std::cout << "-> min(wi0, wi1) = " << eve::min(wi0, wi1) << "\n";
std::cout << "-> min(0.,1.,2.,3.,-3.,-4.,-6.0) = " << eve::min(0.0, 1.0, 2.0, 3.0, -3.0, -4., -6.0) << "\n";
}

◆ minabs

auto eve::minabs = functor<minabs_t>
inlineconstexpr

Computes the minimum of the absolute value of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto minabs(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto minabs(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto minabs[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto minabs[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto minabs[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto minabs[numeric ](/* any of the above overloads */) noexcept; // 5
constexpr auto minabs[widen](/* any of the above overloads */) noexcept; // 6
constexpr auto maxabs[drastic](/* any of the above overloads */) noexcept; // 7
}
constexpr auto minabs
Computes the minimum of the absolute value of its arguments.
Definition minabs.hpp:98

Parameters

Return value

  1. the value of the minimum of the absolute values is returned. If one of the elements is NaN the result is system dependent.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. Ensures conformity to the standard. That is for two parameters to be equivalent to: (|x| < |y|) ? |x| : |y| and this behaviour is also ensured on n parameters calls as if this scheme was recursively used. If one of the arguments is \(\pm0\) returns \(0\) even if some other arguments are NaNs.
  5. NaNs are considered greater than anything else.
  6. compute the upgraded result if available.
  7. returns NaN as soon as one of the parameters is a NaN.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> minabs(wf0, wf1) = " << eve::minabs(wf0, wf1) << "\n";
std::cout << "-> minabs[ignore_last(2)](wf0, wf1) = " << eve::minabs[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> minabs[wf0 != 0](wf0, wf1) = " << eve::minabs[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> minabs[pedantic](wf0, wf1) = " << eve::minabs[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> minabs[numeric ](wf0, wf1) = " << eve::minabs[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> minabs(wu0, wu1) = " << eve::minabs(wu0, wu1) << "\n";
std::cout << "-> minabs(wi0, wi1) = " << eve::minabs(wi0, wi1) << "\n";
float o = 1.0f;
float i = eve::inf(eve::as(o));
float n = eve::nan(eve::as(o));
float z = eve::zero(eve::as(o));
float m = (eve::valmax(eve::as(o))/3)*2;
std::cout << "<- o = " << o << "\n";
std::cout << "-> i = " << i << "\n";
std::cout << "-> n = " << n << "\n";
std::cout << "-> minabs(i, o, -i) = " << eve::minabs(i, o, -i) << "\n";
std::cout << "-> minabs(i, o, n) = " << eve::minabs(i, o, -i) << "\n";
std::cout << "-> minabs[pedantic](o, o, n) = " << eve::minabs[eve::pedantic](o, o, n) << "\n";
std::cout << "-> minabs[pedantic](o, n, o) = " << eve::minabs[eve::pedantic](o, n, o) << "\n";
std::cout << "-> minabs[pedantic](n, o, o) = " << eve::minabs[eve::pedantic](n, o, o) << "\n";
std::cout << "-> minabs[numeric ](o, o, n) = " << eve::minabs[eve::numeric ](o, o, n) << "\n";
std::cout << "-> minabs[numeric](o, n, o) = " << eve::minabs[eve::numeric](o, n, o) << "\n";
std::cout << "-> minabs[numeric](n, o, o) = " << eve::minabs[eve::numeric](n, o, o) << "\n";
std::cout << "-> minabs (o, o, n) = " << eve::minabs(o, o, n) << "\n";
std::cout << "-> minabs (o, n, o) = " << eve::minabs(o, n, o) << "\n";
std::cout << "-> minabs (n, o, o) = " << eve::minabs(n, o, o) << "\n";
std::cout << "-> minabs(n, n, n) = " << eve::minabs(n, n, n) << "\n";
std::cout << "-> minabs(m, o, o) = " << eve::minabs(m, o, o)<< "\n";
std::cout << "-> minabs(i, o, n) = " << eve::minabs(i, o, n)<< "\n";
std::cout << "-> minabs[drastic](z, o, n) = " << eve::minabs[eve::drastic](z, o, n)<< "\n";
std::cout << "-> minabs[numeric](z, o, n) = " << eve::minabs[eve::numeric](z, o, n)<< "\n";
std::cout << "-> minabs[pedantic](z, o, n) = " << eve::minabs[eve::pedantic](z, o, n)<< "\n";
std::cout << "-> minabs(z, o, n) = " << eve::minabs(z, o, n)<< "\n";
}
constexpr auto zero
Computes the constant 0.
Definition zero.hpp:78

◆ minmag

auto eve::minmag = functor<minmag_t>
inlineconstexpr

Computes the value for which the minimum of the absolute value of its arguments is obtained.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto minmag(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto minmag(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto minmag[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto minmag[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto minmag[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto minmag[numeric ](/* any of the above overloads */) noexcept; // 4
}
constexpr auto minmag
Computes the value for which the minimum of the absolute value of its arguments is obtained.
Definition minmag.hpp:88

Parameters

Return value

  1. The element of greatest absolute value is returned. For instance for two elements:
    • If |x| < |y|, x is returned.
    • If |x| > |y|, y is returned.
    • Otherwise min(x, y) is returned. For n parameters the result is computed as if this scheme was recursively used.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. The behaviour of eve::maxmag[o](x, y) (where o is one of these two options) is identical except that if |x| == |y|, min[o] is used.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> minmag(wf0, wf1) = " << eve::minmag(wf0, wf1) << "\n";
std::cout << "-> minmag[ignore_last(2)](wf0, wf1) = " << eve::minmag[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> minmag[wf0 != 0](wf0, wf1) = " << eve::minmag[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> minmag[pedantic](wf0, wf1) = " << eve::minmag[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> minmag[numeric ](wf0, wf1) = " << eve::minmag[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> minmag(wu0, wu1) = " << eve::minmag(wu0, wu1) << "\n";
std::cout << "-> minmag(wi0, wi1) = " << eve::minmag(wi0, wi1) << "\n";
}

◆ minmax

auto eve::minmax = functor<minmax_t>
inlineconstexpr

Computes the minimum and maximum of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto minmax(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto minmax(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto minmax[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto minmax[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto minmax[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto minmax[numeric ](/* any of the above overloads */) noexcept; // 4
}
constexpr auto minmax
Computes the minimum and maximum of its arguments.
Definition minmax.hpp:121

Parameters

Return value

  1. A kumi::tuple containing the value of the minimum and the maximum of the arguments.
  2. Equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. Equivalent to {min[o], max[o]} where o is one of these two options.
Note
  • If any element of the inputs is a Nan, the corresponding output element is system-dependent.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> minmax(wf0, wf1) = " << eve::minmax(wf0, wf1) << "\n";
std::cout << "-> minmax[ignore_last(2)](wf0, wf1) = " << eve::minmax[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> minmax[wf0 != 0](wf0, wf1) = " << eve::minmax[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> minmax[pedantic](wf0, wf1) = " << eve::minmax[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> minmax[numeric ](wf0, wf1) = " << eve::minmax[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> minmax(wu0, wu1) = " << eve::minmax(wu0, wu1) << "\n";
std::cout << "-> minmax(wi0, wi1) = " << eve::minmax(wi0, wi1) << "\n";
}

Semantic Modifiers

  • Masked Call

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

    Example

    // revision 0
    #include <eve/module/core.hpp>
    #include <iostream>
    int main()
    {
    eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
    eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
    eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
    eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
    eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
    eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
    std::cout << "<- wf0 = " << wf0 << "\n";
    std::cout << "<- wf1 = " << wf1 << "\n";
    std::cout << "<- wi0 = " << wi0 << "\n";
    std::cout << "<- wi1 = " << wi1 << "\n";
    std::cout << "<- wu0 = " << wu0 << "\n";
    std::cout << "<- wu1 = " << wu1 << "\n";
    std::cout << "-> minmax(wf0, wf1) = " << eve::minmax(wf0, wf1) << "\n";
    std::cout << "-> minmax[ignore_last(2)](wf0, wf1) = " << eve::minmax[eve::ignore_last(2)](wf0, wf1) << "\n";
    std::cout << "-> minmax[wf0 != 0](wf0, wf1) = " << eve::minmax[wf0 != 0](wf0, wf1) << "\n";
    std::cout << "-> minmax[pedantic](wf0, wf1) = " << eve::minmax[eve::pedantic](wf0, wf1) << "\n";
    std::cout << "-> minmax[numeric ](wf0, wf1) = " << eve::minmax[eve::numeric ](wf0, wf1) << "\n";
    std::cout << "-> minmax(wu0, wu1) = " << eve::minmax(wu0, wu1) << "\n";
    std::cout << "-> minmax(wi0, wi1) = " << eve::minmax(wi0, wi1) << "\n";
    }

◆ minus

auto eve::minus = functor<minus_t>
inlineconstexpr

Computes the opposite of the parameter that must be signed.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto minus(value auto x) noexcept; // 1
// Lanes masking
constexpr auto minus[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto minus[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto minus[saturated](value auto x) noexcept; // 3
constexpr auto minus[mod = p](value auto x) noexcept; // 4
}
constexpr auto minus
Computes the opposite of the parameter that must be signed.
Definition minus.hpp:89

Parameters

Return value

  1. The result is the opposite of x if this value is representable in the type of x. More specifically, for signed integers the opposite value of their lowest finite value is not representable and the result is incorrect (in this case eve::minus(valmin) is valmin).
  2. The operation is performed conditionally.
  3. The saturated version of eve::minus. More specifically, for any signed integer value x, the expression minus[saturated](valmin(as(x))) evaluates to valmax(as(x)).
  4. compute the result in modular arithmetic. the parameter must be flint positive and less than the modulus. The modulus itself must be less than maxflint.
Note
Although the operator notation with - is supported, the - operator on standard scalar type is the original one and so can lead to automatic promotion. Also contrarily to - on signed scalar integral values, eve::minus is never undefined behaviour.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> minus(wf0) = " << eve::minus(wf0) << "\n";
std::cout << "-> minus[ignore_last(2)](wf0) = " << eve::minus[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> minus[wf0 != 0](wf0) = " << eve::minus[wf0 != 0](wf0) << "\n";
std::cout << "-> minus(wu0) = " << eve::minus(wu0) << "\n";
std::cout << "-> minus[ignore_last(2)](wu0) = " << eve::minus[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> minus[wu0 != 0](wu0) = " << eve::minus[wu0 != 0](wu0) << "\n";
std::cout << "-> minus[saturated](wu0) = " << eve::minus[eve::saturated](wu0) << "\n";
std::cout << "-> minus(wi0) = " << eve::minus(wi0) << "\n";
std::cout << "-> minus[ignore_last(2)](wi0) = " << eve::minus[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> minus[wi0 != 0](wi0) = " << eve::minus[wi0 != 0](wi0) << "\n";
std::cout << "-> minus[saturated](wi0) = " << eve::minus[eve::saturated](wi0) << "\n";
}

◆ modf

auto eve::modf = functor<modf_t>
inlineconstexpr

elementwise_callable object computing the elementwise pair of fractional and integral parts of the value,

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto modf(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto modf[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto modf[logical_value auto m](floating_value auto x) noexcept; // 2
// Semantic options
constexpr auto modf[raw](floating_value auto x) noexcept; // 3
constexpr auto modf[pedantic](floating_value auto x) noexcept; // 3
constexpr auto modf[almost](floating_value auto x) noexcept; // 3
}
constexpr auto modf
elementwise_callable object computing the elementwise pair of fractional and integral parts of the va...
Definition modf.hpp:79

Parameters

  • x : real argument.

Return value

  1. A kumi::tuple of values containing respectively the frac(x) and trunc(x),
  2. [The operation is performed conditionally](@ref conditional).
  3. A kumi::tuple of values containing respectively the frac[o](x) and trunc[o](x) where o is the chosen option.

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{-0.0f, 1.30f, -1.3f, eve::inf(eve::as<float>()),
0.0f, eve::nan(eve::as<float>()), 2.0f, eve::prev(2.0f)};
eve::wide wf1{-0.0f, 1.30f, -1.3f, eve::valmax(eve::as<float>()),
0.0f, eve::valmin(eve::as<float>()), 2.0f, eve::prev(2.0f)};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> modf(wf0) = " << eve::modf(wf0) << "\n";
std::cout << "-> modf[raw](wf1) = " << eve::modf[eve::raw](wf1) << "\n";
std::cout << "-> modf[pedantic](wf0) = " << eve::modf[eve::pedantic](wf0) << "\n";
std::cout << "-> modf[almost](wf0) = " << eve::modf[eve::almost](wf0) << "\n";
}
constexpr auto valmin
Computes the lowest representable value.
Definition valmin.hpp:67
constexpr auto prev
Computes the nth previous representable element.
Definition prev.hpp:102

◆ mul

auto eve::mul = functor<mul_t>
inlineconstexpr

tuple_callable computing the product of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto mul(value auto x, value auto ... xs) noexcept; // 1
constexpr auto mul(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto mul[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto mul[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto mul[saturated](/*any of the above overloads*/) noexcept; // 4
constexpr auto mul[lower](/*any of the above overloads*/) noexcept; // 5
constexpr auto mul[upper](/*any of the above overloads*/) noexcept; // 6
constexpr auto mul[lower][strict](/*any of the above overloads*/) noexcept; // 5
constexpr auto mul[upper][strict](/*any of the above overloads*/) noexcept; // 6
constexpr auto mul[widen](/*any of the above overloads*/) noexcept; // 7
constexpr auto mul[mod = p](/*any of the above overloads*/) noexcept; // 8
}

Parameters

Return value

The value of the product of the arguments is returned.

  1. Take care that for floating entries, the multiplication is not perfectly associative due to rounding errors. This call performs multiplications in reverse incoming order.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. The call mul[saturated](...) computes a saturated version of mul. Take care that for signed integral entries this kind of multiplication is not associative at all. This call perform saturated multiplications in reverse incoming order.
  5. The product is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  6. The product is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  7. The operation is computed in the double sized element type (if available). This decorator has no effect on double and 64 bits integrals.
  8. compute the result in modular arithmetic. the parameters must be flint positive and less than the modulus. The modulus itself must be less than maxflint.
Note
Although the infix notation with * is supported for two parameters, the * operator on standard scalar types is the original one and so can lead to automatic promotion.

Example

// revision 0
#include <eve/module/core.hpp>
#include <eve/module/math.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> mul(wf0, wf1) = " << eve::mul(wf0, wf1) << "\n";
std::cout << "-> mul[ignore_last(2)](wf0, wf1) = " << eve::mul[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> mul[wf0 != 0](wf0, wf1) = " << eve::mul[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> mul(wu0, wu1) = " << eve::mul(wu0, wu1) << "\n";
std::cout << "-> mul(wi0, wi1) = " << eve::mul(wi0, wi1) << "\n";
std::cout << "-> mul(wu0, wu1) = " << eve::mul(wu0, wu1) << "\n";
std::cout << "-> mul[widen](wu0, wu1) = " << eve::mul[eve::widen](wu0, wu1) << "\n";
std::cout << "-> mul(wf0, wf1) = " << eve::mul(wf0, wf1) << "\n";
std::cout << "-> mul[widen](wf0, wf1) = " << eve::mul[eve::widen](wf0, wf1) << "\n";
std::cout << std::setprecision(15);
auto l2 = eve::log_2(eve::as<float>());
auto tup = kumi::tuple{pi, e, 1.2345f, l2, pi, e, 1.2345f, l2, 1.35f*pi, l2+pi, 0.07856f};
std::cout << "-> mul[kahan](tup) = " << eve::mul[eve::kahan](tup) << "\n";
std::cout << "-> mul(tup) = " << eve::mul(tup) << "\n";
std::cout << "-> mul[widen](tup) = " << float(eve::mul[eve::widen](tup)) << "\n";
auto z = kumi::tuple{wf0, wf1, wf1};
std::cout << "-> mul[kahan](wf0, wf1, wf1) = " << eve::mul[eve::kahan](z) << "\n";
std::cout << "-> mul[kahan](wf0, wf1, wf1) = " << eve::mul[eve::kahan](wf0, wf1, wf1) << "\n";
}
constexpr auto euler
Callable object computing the constant e basis of the natural logarithms.
Definition euler.hpp:80
constexpr auto pi
Callable object computing the constant .
Definition pi.hpp:79
constexpr auto log_2
Callable object computing the constant .
Definition log_2.hpp:76

◆ nearest

auto eve::nearest = functor<nearest_t>
inlineconstexpr

strict_elementwise_callable object computing the nearest integer to the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto nearest(value auto x) noexcept; // 1
// Lanes masking
constexpr auto nearest[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto nearest[logical_value auto m](value auto x) noexcept; // 2
}
constexpr auto nearest
strict_elementwise_callable object computing the nearest integer to the input.
Definition nearest.hpp:79

Return value

  1. the integer nearest to x. If x is an exact half-integer the rounding is made to the nearest even integer.The smallest integer not less than x. The standard proposes 4 rounding modes namely: FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO. This function object implements the FE_TONEAREST version.
  2. The operation is performed conditionally.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> nearest(wf0) = " << eve::nearest(wf0) << "\n";
std::cout << "-> nearest[ignore_last(2)](wf0) = " << eve::nearest[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> nearest[wf0 != 0](wf0) = " << eve::nearest[wf0 != 0](wf0) << "\n";
std::cout << "-> nearest(wu0) = " << eve::nearest(wu0) << "\n";
std::cout << "-> nearest[ignore_last(2)](wu0) = " << eve::nearest[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> nearest[wu0 != 0](wu0) = " << eve::nearest[wu0 != 0](wu0) << "\n";
std::cout << "-> nearest(wi0) = " << eve::nearest(wi0) << "\n";
std::cout << "-> nearest[ignore_last(2)](wi0) = " << eve::nearest[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> nearest[wi0 != 0](wi0) = " << eve::nearest[wi0 != 0](wi0) << "\n";
}

◆ negabsmax

auto eve::negabsmax = functor<negabsmax_t>
inlineconstexpr

tuple_callable computing the negated absolute value of the maximal element.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto negabsmax(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto negabsmax(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto negabsmax[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto negabsmax[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic option
constexpr auto negabsmax[saturated](/* any of the above overloads */) noexcept; // 4
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto negabsmax[pedantic](/* any of the above overloads */) noexcept; // 5.1
constexpr auto negabsmax[numeric ](/* any of the above overloads */) noexcept; // 5.2
}
constexpr auto negabsmax
tuple_callable computing the negated absolute value of the maximal element.
Definition negabsmax.hpp:92

Parameters

Return value

The negated absolute value of the maximal element is returned.

  1. If any element of the inputs is a NaN the corresponding output element is system-dependent
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. computation internally uses abs[saturated] instead of abs
  5. with numeric (resp. pedantic) max[numeric] (5.1) (resp. max[pedantic] (5.2)) is used internally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> negabsmax(wf0, wf1) = " << eve::negabsmax(wf0, wf1) << "\n";
std::cout << "-> negabsmax[ignore_last(2)](wf0, wf1) = " << eve::negabsmax[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> negabsmax[wf0 != 0](wf0, wf1) = " << eve::negabsmax[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> negabsmax[pedantic](wf0, wf1) = " << eve::negabsmax[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> negabsmax[numeric ](wf0, wf1) = " << eve::negabsmax[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> negabsmax(wu0, wu1) = " << eve::negabsmax(wu0, wu1) << "\n";
std::cout << "-> negabsmax(wi0, wi1) = " << eve::negabsmax(wi0, wi1) << "\n";
}

◆ negabsmin

auto eve::negabsmin = functor<negabsmin_t>
inlineconstexpr

tuple_callable computing the negated absolute value of the minimal element.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto negabsmin(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto negabsmin(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto negabsmin[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto negabsmin[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic options
constexpr auto negabsmin[saturated](/* any of the above overloads */) noexcept; // 4
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto negabsmin[pedantic](/* any of the above overloads */) noexcept; // 5.1
constexpr auto negabsmin[numeric ](/* any of the above overloads */) noexcept; // 5.2
}
constexpr auto negabsmin
tuple_callable computing the negated absolute value of the minimal element.
Definition negabsmin.hpp:92

Parameters

Return value

The negated absolute value of the minimal element is returned.

  1. If any element of the inputs is a NaN the corresponding output element is system-dependent
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. computation internally uses abs[saturated] instead of abs
  5. with numeric (resp. pedantic) min[numeric] (5.1) (resp. min[pedantic] (5.2)) is used internally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> negabsmin(wf0, wf1) = " << eve::negabsmin(wf0, wf1) << "\n";
std::cout << "-> negabsmin[ignore_last(2)](wf0, wf1) = " << eve::negabsmin[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> negabsmin[wf0 != 0](wf0, wf1) = " << eve::negabsmin[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> negabsmin[pedantic](wf0, wf1) = " << eve::negabsmin[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> negabsmin[numeric ](wf0, wf1) = " << eve::negabsmin[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> negabsmin(wu0, wu1) = " << eve::negabsmin(wu0, wu1) << "\n";
std::cout << "-> negabsmin(wi0, wi1) = " << eve::negabsmin(wi0, wi1) << "\n";
}

◆ negate

auto eve::negate = functor<negate_t>
inlineconstexpr

elementwise_callable object computing the product of the first parameter by the sign of the second.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto negate(value auto x, value auto y) noexcept; // 1
// Lanes masking
constexpr auto negate[conditional_expr auto c](value auto x, value auto y) noexcept; // 2
constexpr auto negate[logical_value auto m](value auto , value auto yx) noexcept; // 2
}
constexpr auto negate
elementwise_callable object computing the product of the first parameter by the sign of the second.
Definition negate.hpp:74

Parameters

Return value

  1. The elementwise product of the first parameter by the sign of the second is returned.
  2. The operation is performed conditionally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> negate(wf0, wf1) = " << eve::negate(wf0, wf1) << "\n";
std::cout << "-> negate[ignore_last(2)](wf0, wf1) = " << eve::negate[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> negate[wf0 != 0](wf0, wf1) = " << eve::negate[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> negate(wu0, wu1) = " << eve::negate(wu0, wu1) << "\n";
std::cout << "-> negate[ignore_last(2)](wu0, wu1) = " << eve::negate[eve::ignore_last(2)](wu0, wu1) << "\n";
std::cout << "-> negate[wu0 != 0](wu0, wu1) = " << eve::negate[wu0 != 0](wu0, wu1) << "\n";
std::cout << "-> negate(wi0, wi1) = " << eve::negate(wi0, wi1) << "\n";
std::cout << "-> negate[ignore_last(2)](wi0, wi1) = " << eve::negate[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> negate[wi0 != 0](wi0, wi1) = " << eve::negate[wi0 != 0](wi0, wi1) << "\n";
}

◆ negatenz

auto eve::negatenz = functor<negatenz_t>
inlineconstexpr

elementwise_callable object computing the product of the first parameter by the never zero sign of the second.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto negatenz(value auto x, value auto y) noexcept; // 1
// Lanes masking
constexpr auto negatenz[conditional_expr auto c](value auto x, value auto y) noexcept; // 2
constexpr auto negatenz[logical_value auto m](value auto , value auto yx) noexcept; // 2
}
constexpr auto negatenz
elementwise_callable object computing the product of the first parameter by the never zero sign of th...
Definition negatenz.hpp:70

Parameters

Return value

  1. The elementwise product of the first parameter by the never zero sign of the second is returned.
  2. The operation is performed conditionally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> negatenz(wf0, wf1) = " << eve::negatenz(wf0, wf1) << "\n";
std::cout << "-> negatenz[ignore_last(2)](wf0, wf1) = " << eve::negatenz[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> negatenz[wf0 != 0](wf0, wf1) = " << eve::negatenz[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> negatenz(wu0, wu1) = " << eve::negatenz(wu0, wu1) << "\n";
std::cout << "-> negatenz[ignore_last(2)](wu0, wu1) = " << eve::negatenz[eve::ignore_last(2)](wu0, wu1) << "\n";
std::cout << "-> negatenz[wu0 != 0](wu0, wu1) = " << eve::negatenz[wu0 != 0](wu0, wu1) << "\n";
std::cout << "-> negatenz(wi0, wi1) = " << eve::negatenz(wi0, wi1) << "\n";
std::cout << "-> negatenz[ignore_last(2)](wi0, wi1) = " << eve::negatenz[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> negatenz[wi0 != 0](wi0, wi1) = " << eve::negatenz[wi0 != 0](wi0, wi1) << "\n";
}

◆ negmaxabs

auto eve::negmaxabs = functor<negmaxabs_t>
inlineconstexpr

tuple_callable object computing the negated value of the element of maximal absolute value.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto negmaxabs(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto negmaxabs(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto negmaxabs[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto negmaxabs[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic option
constexpr auto negmaxabs[saturated](/* any of the above overloads */) noexcept; // 4
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto negmaxabs[pedantic](/* any of the above overloads */) noexcept; // 5.1
constexpr auto negmaxabs[numeric ](/* any of the above overloads */) noexcept; // 5.2
}
constexpr auto negmaxabs
tuple_callable object computing the negated value of the element of maximal absolute value.
Definition negmaxabs.hpp:87

Parameters

Return value

The negated value of the element of maximal absolute value is returned.

  1. If any element of the inputs is a NaN the corresponding output element is system-dependent
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. computation internally uses abs[saturated] instead of abs
  5. with numeric (resp. pedantic) max[numeric] (5.1) (resp. max[pedantic] (5.2)) is used internally

    Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> negmaxabs(wf0, wf1) = " << eve::negmaxabs(wf0, wf1) << "\n";
std::cout << "-> negmaxabs[ignore_last(2)](wf0, wf1) = " << eve::negmaxabs[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> negmaxabs[wf0 != 0](wf0, wf1) = " << eve::negmaxabs[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> negmaxabs[pedantic](wf0, wf1) = " << eve::negmaxabs[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> negmaxabs[numeric ](wf0, wf1) = " << eve::negmaxabs[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> negmaxabs(wu0, wu1) = " << eve::negmaxabs(wu0, wu1) << "\n";
std::cout << "-> negmaxabs(wi0, wi1) = " << eve::negmaxabs(wi0, wi1) << "\n";
}

◆ negminabs

auto eve::negminabs = functor<negminabs_t>
inlineconstexpr

tuple_callable computing the negated value of the element of minimal absolute value.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto negminabs(eve::value auto x, eve::value auto ... xs) noexcept; // 1
constexpr auto negminabs(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto negminabs[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto negminabs[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic option
constexpr auto negminabs[saturated](/* any of the above overloads */) noexcept; // 4
// Exclusive Semantic options - Only one of those can be set at once
constexpr auto negminabs[pedantic](/* any of the above overloads */) noexcept; // 5.1
constexpr auto negminabs[numeric ](/* any of the above overloads */) noexcept; // 5.2
}
constexpr auto negminabs
tuple_callable computing the negated value of the element of minimal absolute value.
Definition negminabs.hpp:88

Parameters

Return value

The negated value of the element of minimal absolute value is returned.

  1. If any element of the inputs is a NaN the corresponding output element is system-dependent
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. computation internally uses abs[saturated] instead of abs
  5. with numeric (resp. pedantic) max[numeric] (5.1) (resp. max[pedantic] (5.2)) is used internally

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> negminabs(wf0, wf1) = " << eve::negminabs(wf0, wf1) << "\n";
std::cout << "-> negminabs[ignore_last(2)](wf0, wf1) = " << eve::negminabs[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> negminabs[wf0 != 0](wf0, wf1) = " << eve::negminabs[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> negminabs[pedantic](wf0, wf1) = " << eve::negminabs[eve::pedantic](wf0, wf1) << "\n";
std::cout << "-> negminabs[numeric ](wf0, wf1) = " << eve::negminabs[eve::numeric ](wf0, wf1) << "\n";
std::cout << "-> negminabs(wu0, wu1) = " << eve::negminabs(wu0, wu1) << "\n";
std::cout << "-> negminabs(wi0, wi1) = " << eve::negminabs(wi0, wi1) << "\n";
}

◆ neville

auto eve::neville = functor<neville_t>
inlineconstexpr

callable computing the value of the interpolation polynomial \(p\) of degree n, satisfying: \(p(x_i) = y_i\) for \(i = 0..n\)

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto neville(auto x, auto const& xs..., auto const& ys...) noexcept; // 1
constexpr auto neville(auto x, eve::non_empty_product_type auto const& xx, eve::non_empty_product_type auto const& yy) noexcept; // 2
}
constexpr auto neville
callable computing the value of the interpolation polynomial of degree n, satisfying: for
Definition neville.hpp:88

Parameters

Return value

  • 1. Return the value at x of the polynomial \(p\) of degree n, satisfying \(p(x_i) = y_i\) for \(i = 0..n\), where n+1 is the common number of xs, ys.
  • 2. Same as 1., using the tuple elements.

External references

// revision 1 TODO
#include <eve/module/math.hpp>
#include <iostream>
#include <iomanip>
int main()
{
{
kumi::tuple xd{1.0, 2.0};
kumi::tuple yd = kumi::map([](auto x){return 2*x+1; }, xd);
eve::wide<double, eve::fixed<4>> x(0.5, 2.0, -2.5, 5.0);
std::cout << "<- xd = " << xd << '\n';
std::cout << "<- yd = " << yd << '\n';
std::cout << "<- x = " << x << '\n';
std::cout << "-> neville(x, xd, yd) = " << eve::neville(x, 1.0, 2.0, 3.0, 5.0)<< '\n';
std::cout << "-> neville(x, xd, yd) = " << eve::neville(x, kumi::cat(xd, yd)) << '\n';
std::cout << "-> neville(x, xd, yd) = " << eve::neville(x, xd, yd) << '\n';
}
{
kumi::tuple xd{1.0, 2.0, 3.0, 4.0};
kumi::tuple yd = kumi::map([](auto x){return x*x; }, xd);
eve::wide<double, eve::fixed<8>> x(0.5, 2.0, -2.5, 5.0,0.5, 2.0, -2.5, 5.0 );
std::cout << "<- xd = " << xd << '\n';
std::cout << "<- yd = " << yd << '\n';
std::cout << "<- x = " << x << '\n';
std::cout << "-> neville(x, xd, yd) = " << eve::neville(x, 1.0, 2.0, 3.0, 4.0, 1.0, 4.0, 9.0, 16.0) << '\n';
std::cout << "-> neville(x, xd, yd) = " << eve::neville(x, kumi::cat(xd, yd)) << '\n';
std::cout << "-> neville(x, xd, yd) = " << eve::neville(x, xd, yd) << '\n';
}
}
constexpr cat_t cat

◆ oneminus

auto eve::oneminus = functor<oneminus_t>
inlineconstexpr

elementwise_callable computing the value of one minus the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto oneminus(value auto x) noexcept; // 1
// Lanes masking
constexpr auto oneminus[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto oneminus[logical_value auto m](value auto x) noexcept; // 2
// Semantic option
constexpr auto oneminus[saturated ](value auto x) noexcept; // 3
constexpr auto oneminus[lower](value auto x) noexcept; // 4
constexpr auto oneminus[upper](value auto x) noexcept; // 5
constexpr auto oneminus[lower][strict](value auto x) noexcept; // 4
constexpr auto oneminus[upper][strict](value auto x) noexcept; // 5
constexpr auto oneminus[mod = p](value auto x) noexcept; // 6
}
constexpr auto oneminus
elementwise_callable computing the value of one minus the input.
Definition oneminus.hpp:99

Parameters

Return value

  1. The value of 1-x is returned.
  2. The operation is performed conditionally.
  3. saturated version.
  4. The operation is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  5. The operation is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater or equal to the exact one (except for Nans). Combined with strict the option ensures generally faster computation, but strict inequality.
  6. compute the result in modular arithmetic. the parameter must be flint positive and less than the modulus. The modulus itself must be less than maxflint.
Note
If an element of the expected result is not representable in the result type, the corresponding result element is undefined.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
auto sml = eve::smallestposval(eve::as(1.0));
eve::wide wf0{sml, -sml, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wf1{0.0, 34.0, 0.0, 72.0, 4.0, 3.0, 2.0, 96.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> oneminus(wf0) = " << eve::oneminus(wf0) << "\n";
std::cout << "-> oneminus[ignore_last(2)](wf0) = " << eve::oneminus[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> oneminus[wf0 != 0](wf0) = " << eve::oneminus[wf0 != 0](wf0) << "\n";
std::cout << "-> oneminus[saturated ](wf0) = " << eve::oneminus[eve::saturated ](wf0) << "\n";
std::cout << "-> oneminus(wu0) = " << eve::oneminus(wu0) << "\n";
std::cout << "-> oneminus(wi0) = " << eve::oneminus(wi0) << "\n";
std::cout << std::setprecision(20) << "-> oneminus[lower](wf0) = " << eve::oneminus[eve::lower](wf0) << "\n";
std::cout << std::setprecision(20) << "-> oneminus[upper](wf0) = " << eve::oneminus[eve::upper](wf0) << "\n";
std::cout << std::setprecision(20) << "-> oneminus[lower][strict](wf0) = " << eve::oneminus[eve::lower][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> oneminus[upper][strict](wf0) = " << eve::oneminus[eve::upper][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> oneminus[mod = 97](wf1) = " << eve::oneminus[eve::mod = 97](wf1) << "\n";
}

◆ rat

auto eve::rat = functor<rat_t>
inlineconstexpr

elementwise_callable object computing a rational approximation.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto rat(floating_value auto x) noexcept;
constexpr auto rat(floating_value auto x, floating_value auto tol) noexcept;
}
constexpr auto rat
elementwise_callable object computing a rational approximation.
Definition rat.hpp:79

Parameters

Return value

A tuple-like whose members have the same type as x, containing the numerator and denominator of the rational number approximating x.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> rat(wf0) = " << eve::rat(wf0) << "\n";
std::cout << "-> rat(wf0, wf1) = " << eve::rat(wf0, wf1) << "\n";
}

◆ rec

auto eve::rec = functor<rec_t>
inlineconstexpr

Computes the inverse of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto rec(value auto x) noexcept; // 1
// Lanes masking
constexpr auto rec[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto rec[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto rec[raw](value auto x) noexcept; // 3
constexpr auto rec[pedantic](value auto x) noexcept; // 4
constexpr auto rec[lower](floating_value auto x) noexcept; // 5
constexpr auto rec[upper](floating_value auto x) noexcept; // 6
constexpr auto rec[mod = p](floating_value auto x) noexcept; // 7
constexpr auto rec[widen](floating_value auto x) noexcept; // 8
}
constexpr auto rec
Computes the inverse of the parameter.
Definition rec.hpp:94

Parameters

Return value

  1. The value of the inverse of x is returned; denormals may not be handled.
  2. The operation is performed conditionally.
  3. Calls a system intrinsic if one exists; this may return reduced accuracy (roughly 12 bits). Otherwise, the regular implementation is used.
  4. Equivalent to dividing one(as(x)) by x.
  5. The inverse is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less than or equal to the exact value (except for NaNs).
  6. The inverse is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater than or equal to the exact value (except for NaNs).
  7. Computes the result in modular arithmetic. the parameters must be flint positive and less than the modulus. The modulus itself must be less than maxflint. Note that mul[mod = p](a, rec[mod = p](a)) is the gcd of p and a (1 iff a and p are coprime)
  8. The inverse is computed in the double sized element type (if available). This decorator has no effect on double and 64 bits integrals.//!
    Note
    For integral value rec(x) is equivalent to:

    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, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> rec(wf0) = " << eve::rec(wf0) << "\n";
std::cout << "-> rec[ignore_last(2)](wf0) = " << eve::rec[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> rec[wf0 != 0](wf0) = " << eve::rec[wf0 != 0](wf0) << "\n";
std::cout << "-> rec[raw](wf0) = " << eve::rec[eve::raw](wf0) << "\n";
std::cout << "-> rec[pedantic](wf0) = " << eve::rec[eve::pedantic](wf0) << "\n";
std::cout << "-> rec(wu0) = " << eve::rec(wu0) << "\n";
std::cout << "-> rec[ignore_last(2)](wu0) = " << eve::rec[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> rec[wu0 != 0](wu0) = " << eve::rec[wu0 != 0](wu0) << "\n";
std::cout << "-> rec[raw](wu0) = " << eve::rec[eve::raw](wu0) << "\n";
std::cout << "-> rec[pedantic](wu0) = " << eve::rec[eve::pedantic](wu0) << "\n";
std::cout << "-> rec(wi0) = " << eve::rec(wi0) << "\n";
std::cout << "-> rec[ignore_last(2)](wi0) = " << eve::rec[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> rec[wi0 != 0](wi0) = " << eve::rec[wi0 != 0](wi0) << "\n";
std::cout << "-> rec[raw](wi0) = " << eve::rec[eve::raw](wi0) << "\n";
std::cout << "-> rec[pedantic](wi0) = " << eve::rec[eve::pedantic](wi0) << "\n";
std::cout << std::setprecision(20) << "-> rec[lower](wf1) = " << eve::rec[eve::lower](wf0) << "\n";
std::cout << std::setprecision(20) << "-> rec[upper](wf1) = " << eve::rec[eve::upper](wf0) << "\n";
std::cout << std::setprecision(20) << "-> rec[lower][strict](wf0) = " << eve::rec[eve::lower][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> rec[upper][strict](wf0) = " << eve::rec[eve::upper][eve::strict](wf0) << "\n";
}

◆ reldist

auto eve::reldist = functor<reldist_t>
inlineconstexpr

elementwise_callable object computing the relative distance of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto reldist(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto reldist[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto reldist[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
// Semantic options
constexpr auto reldist[pedantic](floating_value auto x, floating_value auto y) noexcept; // 4
}
constexpr auto reldist
elementwise_callable object computing the relative distance of its arguments.
Definition reldist.hpp:76

Parameters

Return value

  1. The value of the relative distance of the arguments is returned, i.e. eve::abs(x-y)/max(abs(x), abs(y), 1).
  2. The operation is performed conditionally.
  3. reldist[pedantic](x, y) computes a distance which is NaN if and only if one of the parameters is NaN.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> reldist(wf0, wf1) = " << eve::reldist(wf0, wf1) << "\n";
std::cout << "-> reldist[ignore_last(2)](wf0, wf1) = " << eve::reldist[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> reldist[wf0 != 0](wf0, wf1) = " << eve::reldist[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> reldist[pedantic](wf0, wf1) = " << eve::reldist[eve::pedantic](wf0, wf1) << "\n";
}

◆ rem

auto eve::rem = functor<rem_t>
inlineconstexpr

elementwise_callable object computing the remainder after division.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto rem(value auto x, value auto y) noexcept; // 1
// Lanes masking
constexpr auto rem[conditional_expr auto c](value auto x, value auto y) noexcept; // 2
constexpr auto rem[logical_value auto m](value auto x, value auto y) noexcept; // 2
// Semantic option
constexpr auto rem[downward](/*any of the above overloads*/) noexcept; // 3
constexpr auto rem[upward](/*any of the above overloads*/) noexcept; // 3
constexpr auto rem[to_nearest](/*any of the above overloads*/) noexcept; // 3
constexpr auto rem[toward_zero](/*any of the above overloads*/) noexcept; // 3
}
constexpr auto rem
elementwise_callable object computing the remainder after division.
Definition rem.hpp:85

Parameters

Return value

  1. Return the remainder after division of x by y and is equivalent to x-div[toward_zero](x, y)*y.
  2. The operation is performed conditionally.
  3. The call is equivalent to x-div[o](x, y)*y where o is the chosen option. For unsigned integral the options upward and nearest are undefined behaviour as the result could be negative.
Note
Although the infix notation with % is supported, the % operator on standard integral scalar type is the original one and so can lead to automatic promotion. Moreover due to C++ limitations, % is not available for scalar floating point values.

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
w_t pi = {3, 2, 3, 32700}, qi = {4, 2, 1, 101}, ri = {4, 2, 0, 101};
std::cout << " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
<< " <- ri = " << ri << '\n'
<< " -> rem(pi, qi) = " << eve::rem(pi, qi) << '\n'
<< " -> rem[toward_zero](pi, qi) = " << eve::rem[eve::toward_zero](pi, qi) << '\n'
<< " -> rem[downward](pi, qi) = " << eve::rem[eve::downward](pi, qi) << '\n'
<< " -> rem[upward](pi, qi) = " << eve::rem[eve::upward](pi, qi) << '\n'
<< " -> rem[toward_zero](pi, qi) = " << eve::rem[eve::to_nearest](pi, qi) << '\n'
<< " -> pi % qi = " << pi % qi << '\n';
}

◆ remainder

auto eve::remainder = functor<remainder_t>
inlineconstexpr

mimic the std::remainder function for floating values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto remainder(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto remainder[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto remainder[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
}
constexpr auto remainder
mimic the std::remainder function for floating values.
Definition remainder.hpp:74

Parameters

Return value

  1. Returns the remainder after division of x by y and is equivalent to x- eve::nearest(eve::div(x, y))*y. In particular:
    • If x is \(\pm\inf\) or NaN, NaN is returned.
    • If y is \(\pm0\) \(\pm0\) is returned
    • If y is NaN, NaN is returned.
  2. The operation is performed conditionally.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, -4.0, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> remainder(wf0, wf1) = " << eve::remainder(wf0, wf1) << "\n";
std::cout << "-> remainder[ignore_last(2)](wf0, wf1) = " << eve::remainder[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> remainder[wf0 != 0](wf0, wf1) = " << eve::remainder[wf0 != 0](wf0, wf1) << "\n";
}

◆ round

auto eve::round = functor<round_t>
inlineconstexpr

Computes the integer nearest to the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto round(value auto x) noexcept; // 1
// Lanes masking
constexpr auto round[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto round[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto round[upward](floating_value auto x) noexcept; // 3
constexpr auto round[downward](floating_value auto x) noexcept; // 4
constexpr auto round[to_nearest](floating_value auto x) noexcept; // 5
constexpr auto round[toward_zero](floating_value auto x) noexcept; // 6
}
constexpr auto round
Computes the integer nearest to the input.
Definition round.hpp:81

Parameters

Return value

  1. The integer nearest to x.
  2. The operation is performed conditionally.
  3. equivalent to ceil(x).
  4. equivalent to floor(x).
  5. equivalent to nearest(x).
  6. equivalent to trunc(x).

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> round(wf0) = " << eve::round(wf0) << "\n";
std::cout << "-> round[ignore_last(2)](wf0) = " << eve::round[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> round[wf0 != 0](wf0) = " << eve::round[wf0 != 0](wf0) << "\n";
std::cout << "-> round[upward](wf0) = " << eve::round[eve::upward](wf0) << "\n";
std::cout << "-> round[downward](wf0) = " << eve::round[eve::downward](wf0) << "\n";
std::cout << "-> round[to_nearest](wf0) = " << eve::round[eve::to_nearest](wf0) << "\n";
std::cout << "-> round[toward_zero](wf0) = " << eve::round[eve::toward_zero](wf0) << "\n";
std::cout << "-> round(wu0) = " << eve::round(wu0) << "\n";
std::cout << "-> round[ignore_last(2)](wu0) = " << eve::round[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> round[wu0 != 0](wu0) = " << eve::round[wu0 != 0](wu0) << "\n";
std::cout << "-> round(wi0) = " << eve::round(wi0) << "\n";
std::cout << "-> round[ignore_last(2)](wi0) = " << eve::round[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> round[wi0 != 0](wi0) = " << eve::round[wi0 != 0](wi0) << "\n";
}

◆ roundscale

auto eve::roundscale = functor<roundscale_t>
inlineconstexpr

strict_elementwise_callable object computing the scaled input rounding.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto roundscale(floating_value auto x, index_t<scale>) noexcept; // 1
constexpr auto roundscale(floating_value auto x, integral_value scale) noexcept; // 1
// Semantic option
constexpr auto roundscale[downward](/*any of the above overloads*/) noexcept; // 2
constexpr auto roundscale[upward](/*any of the above overloads*/) noexcept; // 2
constexpr auto roundscale[to_nearest](/*any of the above overloads*/) noexcept; // 2
constexpr auto roundscale[toward_zero](/*any of the above overloads*/) noexcept; // 2
}
constexpr auto roundscale
strict_elementwise_callable object computing the scaled input rounding.
Definition roundscale.hpp:80

Parameters

  • x: floating value.
  • scale : inttegal value or integral_constant of integral type.

Return value

  1. Returns the elementwise scaled input. The number of fraction bits retained is specified by scale. By default the internal rounding after scaling is done to nearest integer. The call roundscale(x, scale) is equivalent to ldexp(eve::nearest(ldexp(x,scale), -scale))
  2. with o denoting one of these options the call is equivalent to ldexp(round[o](ldexp(x,scale), -scale))

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0(0.0f, 1.0f, 2.0f, 3.0f, 4.0f, 5.0f, 6.0f, 7.0f);
wf0+= 1.2345678;
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> roundscale(wf0, index_t<0>()) = " << eve::roundscale(wf0, eve::index_t<0>()) << "\n";
std::cout << "-> roundscale(wf0, 2*wi) = " << eve::roundscale(wf0, wu0) << "\n";
std::cout << "-> roundscale[downward](wf0, index_t<0>()) = " << eve::roundscale[eve::downward](wf0, eve::index_t<0>()) << "\n";
std::cout << "-> roundscale[upward](wf0, index_t<0>()) = " << eve::roundscale[eve::upward](wf0, eve::index_t<0>()) << "\n";
std::cout << "-> roundscale[to_nearest](wf0, index_t<0>()) = " << eve::roundscale[eve::to_nearest](wf0, eve::index_t<0>()) << "\n";
std::cout << "-> roundscale[toward_zero](wf0, index_t<0>()) = " << eve::roundscale[eve::toward_zero](wf0, eve::index_t<0>()) << "\n";
}

◆ rsqrt

auto eve::rsqrt = functor<rsqrt_t>
inlineconstexpr

Computes the inverse of the square root of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto rsqrt(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto rsqrt[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto rsqrt[logical_value auto m](floating_value auto x) noexcept; // 2
// Semantic options
constexpr auto rsqrt[raw](floating_value auto x) noexcept; // 3
}
constexpr auto rsqrt
Computes the inverse of the square root of the parameter.
Definition rsqrt.hpp:76

Parameters

Return value

  1. A value containing the elementwise inverse of the square root of x.
  2. The operation is performed conditionally.
  3. Calls a proper system intrinsic if one exists, but with possibly very poor accuracy in return. Otherwise, it uses the regular implementation.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "-> rsqrt(wf0) = " << eve::rsqrt(wf0) << "\n";
std::cout << "-> rsqrt[ignore_last(2)](wf0) = " << eve::rsqrt[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> rsqrt[wf0 != 0](wf0) = " << eve::rsqrt[wf0 != 0](wf0) << "\n";
std::cout << "-> rsqrt[raw](wf0) = " << eve::rsqrt[eve::raw](wf0) << "\n";
}

◆ saturate

auto eve::saturate = functor<saturate_t>
inlineconstexpr

strict_elementwise_callable computing the saturation of a value in a type.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto saturate(value auto x, as<value> t) noexcept;
}
constexpr auto saturate
strict_elementwise_callable computing the saturation of a value in a type.
Definition saturate.hpp:78

Parameters

Return value

For an x type U, the call saturate(x, as_<Target>{}) returns elementwise a value of element type U which is x clamped between the smallest and largest values of the Target

Note
Saturation operated by eve::saturate may lead to Undefined Behaviors if it implies conversions that are themselves Undefined Behavior.

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0 = {-1.0f, 2.3f, 45000.7f, -64768.6f};
eve::wide wi0 = {-1l, 2l, -3l, eve::valmax(eve::as<long>())};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "-> saturate(wf0, as(wu)) = " << eve::saturate(wf0, eve::as<std::int16_t>()) << "\n";
std::cout << "-> saturate(wi, as(wu0)) = " << eve::saturate(wi0, eve::as<std::int16_t>()) << "\n";
}

◆ sign

auto eve::sign = functor<sign_t>
inlineconstexpr

elementwise_callable object computing the sign of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sign(value auto x) noexcept; // 1
// Lanes masking
constexpr auto sign[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto sign[logical_value auto m](value auto x) noexcept; // 2
}
constexpr auto sign
elementwise_callable object computing the sign of the parameter.
Definition sign.hpp:76

Parameters

Return value

  1. The elementwise sign of x computed as:
    • +1 , if x is greater than 0
    • -1 , if x is less than 0
    • \(\pm0\), if x is \(\pm0\)
    • If called on Nan, the result is the actual sign of Nan.
  2. The operation is performed conditionally.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> sign(wf0) = " << eve::sign(wf0) << "\n";
std::cout << "-> sign[ignore_last(2)](wf0) = " << eve::sign[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> sign[wf0 != 0](wf0) = " << eve::sign[wf0 != 0](wf0) << "\n";
std::cout << "-> sign(wu0) = " << eve::sign(wu0) << "\n";
std::cout << "-> sign[ignore_last(2)](wu0) = " << eve::sign[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> sign[wu0 != 0](wu0) = " << eve::sign[wu0 != 0](wu0) << "\n";
std::cout << "-> sign(wi0) = " << eve::sign(wi0) << "\n";
std::cout << "-> sign[ignore_last(2)](wi0) = " << eve::sign[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> sign[wi0 != 0](wi0) = " << eve::sign[wi0 != 0](wi0) << "\n";
}

◆ sign_alternate

auto eve::sign_alternate = functor<sign_alternate_t>
inlineconstexpr

Computes \((-1)^n\).

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sign_alternate(signed_value auto n) noexcept; // 1
// Semantic options
constexpr auto sign_alternate[downward](signed_value auto n) noexcept; // 2
constexpr auto sign_alternate[upward](signed_value auto n) noexcept; // 2
constexpr auto sign_alternate[to_nearest](signed_value auto n) noexcept; // 2
constexpr auto sign_alternate[toward_zero](signed_value auto n) noexcept; // 2
// Lanes masking
constexpr auto sign_alternate[conditional_expr auto c](signed_value auto n) noexcept; // 3
constexpr auto sign_alternate[logical_value auto m](signed_value auto n) noexcept; // 3
}
The concept signed_value<T> is satisfied if and only if T satisfies eve::value and the element type s...
Definition value.hpp:68
constexpr auto sign_alternate
Computes .
Definition sign_alternate.hpp:79

Parameters

Return value

  1. elementwise \((-1)^\tilde n\) is returned, where \(\tilde n\) is the truncation of n.
  2. The chosen rounding option is applied to n before computation, instead of truncation.
  3. The operation is performed conditionally.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "-> sign_alternate(wf0) = " << eve::sign_alternate(wf0) << "\n";
std::cout << "-> sign_alternate[ignore_last(2)](wf0) = " << eve::sign_alternate[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> sign_alternate[wf0 != 0](wf0) = " << eve::sign_alternate[wf0 != 0](wf0) << "\n";
std::cout << "-> sign_alternate(wi0) = " << eve::sign_alternate(wi0) << "\n";
std::cout << "-> sign_alternate[ignore_last(2)](wi0) = " << eve::sign_alternate[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> sign_alternate[wi0 != 0](wi0) = " << eve::sign_alternate[wi0 != 0](wi0) << "\n";
}

◆ signnz

auto eve::signnz = functor<signnz_t>
inlineconstexpr

elementwise_callable object computing the never zero sign of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto signnz(value auto x) noexcept; // 1
// Lanes masking
constexpr auto signnz[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto signnz[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto abs[pedantic](value auto x) noexcept; // 3
}
constexpr auto signnz
elementwise_callable object computing the never zero sign of the parameter.
Definition signnz.hpp:80

Parameters

Return value

  1. Computes elementwise the never zero sign of x.
  2. The operation is performed conditionally.
  3. same as 1. but returns NaN for NaN input
Note
is_negative and is_positive only look at the sign bit and a NaN has generally unpredictable sign bit.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> signnz(wf0) = " << eve::signnz(wf0) << "\n";
std::cout << "-> signnz[ignore_last(2)](wf0) = " << eve::signnz[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> signnz[wf0 != 0](wf0) = " << eve::signnz[wf0 != 0](wf0) << "\n";
std::cout << "-> signnz(wu0) = " << eve::signnz(wu0) << "\n";
std::cout << "-> signnz[ignore_last(2)](wu0) = " << eve::signnz[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> signnz[wu0 != 0](wu0) = " << eve::signnz[wu0 != 0](wu0) << "\n";
std::cout << "-> signnz(wi0) = " << eve::signnz(wi0) << "\n";
std::cout << "-> signnz[ignore_last(2)](wi0) = " << eve::signnz[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> signnz[wi0 != 0](wi0) = " << eve::signnz[wi0 != 0](wi0) << "\n";
}

◆ sqr

auto eve::sqr = functor<sqr_t>
inlineconstexpr

Computes the square of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sqr(value auto x) noexcept; // 1
// Lanes masking
constexpr auto sqr[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto sqr[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto sqr[saturated](value auto x) noexcept; // 3
constexpr auto sqr[lower](value auto x) noexcept; // 4
constexpr auto sqr[upper](value auto x) noexcept; // 5
constexpr auto add[mod = p](value auto x) noexcept; // 6
}

Parameters

Return value

  1. value containing the elementwise square of x if it is representable in this type.
  2. The operation is performed conditionally.
  3. Contrary to the non-decorated case, it guarantees that the result is elementwise greater or equal than 0. More specifically, for any integer value x, the call evaluates to: valmax(as(x)) as soon as abs[saturated](x) is greater than sqrtvalmax(as(x)).
  4. The square is done in a 'round toward \(-\infty\) mode. The product is guaranteed to be less or equal to the exact one.
  5. The square is done in a 'round toward \(\infty\) mode. The product is guaranteed to be greater or equal to the exact one.
  6. compute the result in modular arithmetic. the parameter must be flint positive and less than the modulus. The modulus itself must be less than maxflint.
Note
For integral signed values if eve::abs[eve::saturated](x) is greater than eve::Sqrtvalmax(as(x)) the corresponding element result is undefined.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{0.0, 34.0, 0.0, 72.0, 4.0, 3.0, 2.0, 96.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> sqr(wf0) = " << eve::sqr(wf0) << "\n";
std::cout << "-> sqr[ignore_last(2)](wf0) = " << eve::sqr[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> sqr[wf0 != 0](wf0) = " << eve::sqr[wf0 != 0](wf0) << "\n";
std::cout << "-> sqr(wu0) = " << eve::sqr(wu0) << "\n";
std::cout << "-> sqr[ignore_last(2)](wu0) = " << eve::sqr[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> sqr[wu0 != 0](wu0) = " << eve::sqr[wu0 != 0](wu0) << "\n";
std::cout << "-> sqr[saturated](wu0) = " << eve::sqr[eve::saturated](wu0) << "\n";
std::cout << "-> sqr(wi0) = " << eve::sqr(wi0) << "\n";
std::cout << "-> sqr[ignore_last(2)](wi0) = " << eve::sqr[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> sqr[wi0 != 0](wi0) = " << eve::sqr[wi0 != 0](wi0) << "\n";
std::cout << "-> sqr[saturated](wi0) = " << eve::sqr[eve::saturated](wi0) << "\n";
std::cout << "-> sqr[mod = 97](wf1) = " << eve::sqr[eve::mod = 97](wf1) << "\n";
}

◆ sqrt

auto eve::sqrt = functor<sqrt_t>
inlineconstexpr

Computes the elementwise square root of the parameter.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sqrt(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto sqrt[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto sqrt[logical_value auto m](floating_value auto x) noexcept; // 2
// Semantic options
constexpr auto sqrt[raw](floating_value auto x) noexcept; // 3
constexpr auto sqrt[lower](floating_value auto x) noexcept; // 4
constexpr auto sqrt[upper](floating_value auto x) noexcept; // 5
}
constexpr auto sqrt
Computes the elementwise square root of the parameter.
Definition sqrt.hpp:86

Parameters

Return value

  1. A floating-point value containing the elementwise square root of x or NaN if x is less than zero.
  2. The operation is performed conditionally.
  3. Calls a proper system intrinsic if one exists, but with possibly very poor accuracy in return. Otherwise, the regular implementation is used.
  4. The square root is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less than or equal to the exact value (except for NaNs).
  5. The square root is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater than or equal to the exact value (except for NaNs).

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, -4.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> sqrt(wf0) = " << eve::sqrt(wf0) << "\n";
std::cout << "-> sqrt[ignore_last(2)](wf0) = " << eve::sqrt[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> sqrt[wf0 != 0](wf0) = " << eve::sqrt[wf0 != 0](wf0) << "\n";
std::cout << "-> sqrt[raw](wf0) = " << eve::sqrt[eve::raw](wf0) << "\n";
std::cout << "-> sqrt(wu0) = " << eve::sqrt(wu0) << "\n";
std::cout << "-> sqrt[ignore_last(2)](wu0) = " << eve::sqrt[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> sqrt[wu0 != 0](wu0) = " << eve::sqrt[wu0 != 0](wu0) << "\n";
std::cout << "-> sqrt[raw](wu0) = " << eve::sqrt[eve::raw](wu0) << "\n";
std::cout << "-> sqrt(wi0) = " << eve::sqrt(wi0) << "\n";
std::cout << "-> sqrt[ignore_last(2)](wi0) = " << eve::sqrt[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> sqrt[wi0 != 0](wi0) = " << eve::sqrt[wi0 != 0](wi0) << "\n";
std::cout << "-> sqrt[raw](wi0) = " << eve::sqrt[eve::raw](wi0) << "\n";
std::cout << std::setprecision(20) << "-> sqrt(wf0) = " << eve::sqrt(wf0) << "\n";
std::cout << std::setprecision(20) << "-> sqrt[lower](wf0) = " << eve::sqrt[eve::lower](wf0) << "\n";
std::cout << std::setprecision(20) << "-> sqrt[upper](wf0) = " << eve::sqrt[eve::upper](wf0) << "\n";
std::cout << std::setprecision(20) << "-> sqrt[lower][strict](wf0) = " << eve::sqrt[eve::lower][eve::strict](wf0) << "\n";
std::cout << std::setprecision(20) << "-> sqrt[upper][strict](wf0) = " << eve::sqrt[eve::upper][eve::strict](wf0) << "\n";
}

◆ sub

auto eve::sub = functor<sub_t>
inlineconstexpr

tuple_callable computing the difference of its first argument with the sum of the others.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto sub(value auto x, value auto ... xs) noexcept; // 1
constexpr auto sub(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto sub[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto sub[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto sub[saturated](/*any of the above overloads*/) noexcept; // 4
constexpr auto sub[lower](/*any of the above overloads*/) noexcept; // 5
constexpr auto sub[upper](/*any of the above overloads*/) noexcept; // 6
constexpr auto sub[widen](/*any of the above overloads*/) noexcept; // 7
constexpr auto sub[right](/*any of the above overloads*/) noexcept; // 1
constexpr auto sub[left](/*any of the above overloads*/) noexcept; // 8
constexpr auto sub[mod = p](/*any of the above overloads*/) noexcept; // 9
}
constexpr auto sub
tuple_callable computing the difference of its first argument with the sum of the others.
Definition sub.hpp:110

Parameters

Return value

The value of the difference of its first argument with the sum of the others

  1. Take care that for floating entries, the addition is not perfectly associative due to rounding errors. This call performs additions in reverse incoming order.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. The call sub[saturated](...) computes a saturated version of add. Take care that for signed integral entries this kind of a is highly order dependent. This call perform saturated additions in reverse incoming order. We do not advise to use it for more than 2 parameters.
  5. The subtraction is computed in a 'round toward \(-\infty\) mode. The result is guaranteed to be less or equal to the exact one (except for Nans).
  6. The subtraction is computed in a 'round toward \(\infty\) mode. The result is guaranteed to be greater or equal to the exact one (except for Nans).
  7. The operation is computed in the double sized element type (if available). This decorator has no effect on double and 64 bits integrals.
  8. sub[left](a, b) is semantically equivalent to sub(b, a)
  9. compute the result in modular arithmetic. the parameters must be floating positive and less than the modulus p. The modulus itself must be less than maxflint.
Note
Although the infix notation with - is supported for two parameters, the - operator on standard scalar types is the original one and so can lead to automatic promotion.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
auto sml = eve::smallestposval(eve::as(1.0));
eve::wide wf0{1.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{sml, -sml, 1.0, -1.0, 2.0, -2.0, 3.0, -3.0};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide wu0{0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide wu1{7u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> sub(wf0, wf1) = " << eve::sub(wf0, wf1) << "\n";
std::cout << "-> sub[left](wf0, wf1) = " << eve::sub[eve::left](wf0, wf1) << "\n";
std::cout << "-> sub[ignore_last(2)](wf0, wf1) = " << eve::sub[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> sub[wf0 != 0](wf0, wf1) = " << eve::sub[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> sub(wu0, wu1) = " << eve::sub(wu0, wu1) << "\n";
std::cout << "-> sub(wi0, wi1) = " << eve::sub(wi0, wi1) << "\n";
std::cout << std::setprecision(20) << "-> sub(wf0, wf1) = " << eve::sub(wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> sub[lower](wf0, wf1) = " << eve::sub[eve::lower](wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> sub[upper](wf0, wf1) = " << eve::sub[eve::upper](wf0, wf1) << "\n";
std::cout << "-> sub(wu0, wu1) = " << eve::sub(wu0, wu1) << "\n";
std::cout << "-> sub[widen](wu0, wu1) = " << eve::sub[eve::widen](wu0, wu1) << "\n";
std::cout << "-> sub(wf0, wf1) = " << eve::sub(wf0, wf1) << "\n";
std::cout << "-> sub[widen](wf0, wf1) = " << eve::sub[eve::widen](wf0, wf1) << "\n";
}

◆ sum_of_squares

auto eve::sum_of_squares = functor<sum_of_squares_t>
inlineconstexpr

tuple_callable object computing the sum of the squared values of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto sum_of_squares(value auto x, value auto ... xs) noexcept; // 1
constexpr auto sum_of_squares(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Semantic options
constexpr auto sum_of_squares[saturated](/*any of the above overloads*/) noexcept; // 3
constexpr auto sum_of_squares[pedantic](/*any of the above overloads*/) noexcept; // 4
constexpr auto sum_of_squares[kahan](/*any of the above overloads*/) noexcept; // 5
}
constexpr auto sum_of_squares
tuple_callable object computing the sum of the squared values of its arguments.
Definition sum_of_squares.hpp:90

Parameters

Return value

  1. The value of the sum of the squared values of the arguments is returned.
  2. equivalent to the call on the elements of the tuple.
  3. internally uses saturated options.
  4. returns \(\infty\) as soon as one of its parameter is infinite, regardless of possible Nan values.
  5. uses kahan like compensated algorithm for better accuracy.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
#include <cfenv>
#include <vector>
int main()
{
eve::wide wf0{1.0f, 1.0f, 2.0f, 3.0f, -1.0f, -2.0f, -3.0f, -4.0f};
eve::wide wf1{eve::eps(eve::as(1.0f))/4, -eve::eps(eve::as(1.0f))/4, 1.0f, -1.0f, 2.0f, -2.0f, 3.0f, -3.0f};
eve::wide wi0{0, 1, 2, 3, -1, -2, -3, -4};
eve::wide wi1{0, -4, 1, -1, 2, -2, 3, -3};
eve::wide<std::uint16_t, eve::fixed<8>> wu0{65534u, 65000u, 2u, 3u, 4u, 5u, 6u, 7u};
eve::wide<std::uint16_t, eve::fixed<8>> wu1{2u, 6u, 5u, 4u, 3u, 2u, 1u, 0u};
std::cout << std::setprecision(15) << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wi1 = " << wi1 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "<- wu1 = " << wu1 << "\n";
std::cout << "-> sum_of_squares(wf0, wf1) = " << eve::sum_of_squares(wf0, wf1) << "\n";
std::cout << "-> sum_of_squares[ignore_last(2)](wf0, wf1) = " << eve::sum_of_squares[eve::ignore_last(2)](wf0, wf1) << "\n";
std::cout << "-> sum_of_squares[wf0 != 0](wf0, wf1) = " << eve::sum_of_squares[wf0 != 0](wf0, wf1) << "\n";
std::cout << "-> sum_of_squares(wu0, wu1) = " << eve::sum_of_squares(wu0, wu1) << "\n";
std::cout << "-> sum_of_squares[saturated](wu0, wu1) = " << eve::sum_of_squares[eve::saturated](wu0, wu1) << "\n";
std::cout << "-> sum_of_squares(wi0, wi1) = " << eve::sum_of_squares(wi0, wi1) << "\n";
std::cout << std::setprecision(20) << "-> sum_of_squares[lower](wf0, wf1) = " << eve::sum_of_squares[eve::lower](wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> sum_of_squares[upper](wf0, wf1) = " << eve::sum_of_squares[eve::upper](wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> sum_of_squares[lower][strict](wf0, wf1) = " << eve::sum_of_squares[eve::lower][eve::strict](wf0, wf1) << "\n";
std::cout << std::setprecision(20) << "-> sum_of_squares[upper][strict](wf0, wf1) = " << eve::sum_of_squares[eve::upper][eve::strict](wf0, wf1) << "\n";
std::cout << "-> sum_of_squares(wu0, wu1) = " << eve::sum_of_squares(wu0, wu1) << "\n";
std::cout << "-> sum_of_squares[widen](wu0, wu1) = " << eve::sum_of_squares[eve::widen](wu0, wu1) << "\n";
std::cout << "-> sum_of_squares(wf0, wf1) = " << eve::sum_of_squares(wf0, wf1) << "\n";
std::cout << "-> sum_of_squares[widen](wf0, wf1) = " << eve::sum_of_squares[eve::widen](wf0, wf1) << "\n";
std::cout << std::setprecision(16);
auto sqteps_2 = eve::sqrteps(eve::as<float>())/2;
std::cout << "-> sum_of_squares(1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2) = " << eve::sum_of_squares(1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2) << "\n";
std::cout << "-> sum_of_squares[kahan](1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2) = " << eve::sum_of_squares[eve::kahan](1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2) << "// float result\n";
std::cout << "-> sum_of_squares[widen](1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2) = " << eve::sum_of_squares[eve::widen](1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2) << "// double result\n";
auto tup = kumi::tuple{1.0f, sqteps_2, sqteps_2, sqteps_2, sqteps_2};
std::cout << "-> sum_of_squares[kahan](tup) = " << eve::sum_of_squares[eve::kahan](tup) << "\n";
float o = 1.0f;
float i = eve::inf(eve::as(o));
float n = eve::nan(eve::as(o));
float v = eve::valmax(eve::as(o));
float z = eve::zero(eve::as(o));
float m = (v/3)*2;
std::cout << "<- o = " << o << "\n";
std::cout << "-> i = " << i << "\n";
std::cout << "-> n = " << n << "\n";
std::cout << "-> m = " << m << "\n";
std::cout << "-> v = " << v << "\n";
std::cout << "-> sum_of_squares(i, o, -i) = " << eve::sum_of_squares(i, o, -i) << "\n";
std::cout << "-> sum_of_squares(i, o, n) = " << eve::sum_of_squares(i, o, n) << "\n";
std::cout << "-> sum_of_squares[pedantic](i, o, -i) = " << eve::sum_of_squares[eve::pedantic](i, o, -i) << "\n";
std::cout << "-> sum_of_squares[pedantic](i, o, n) = " << eve::sum_of_squares[eve::pedantic](i, o, n) << "\n";
std::cout << "-> sum_of_squares[pedantic](o, o, n) = " << eve::sum_of_squares[eve::pedantic](o, o, n) << "\n";
std::cout << "-> sum_of_squares[pedantic](o, n, o) = " << eve::sum_of_squares[eve::pedantic](o, n, o) << "\n";
std::cout << "-> sum_of_squares[pedantic](n, o, o) = " << eve::sum_of_squares[eve::pedantic](n, o, o) << "\n";
std::cout << "-> sum_of_squares (o, o, n) = " << eve::sum_of_squares(o, o, n) << "\n";
std::cout << "-> sum_of_squares (o, n, o) = " << eve::sum_of_squares(o, n, o) << "\n";
std::cout << "-> sum_of_squares (n, o, o) = " << eve::sum_of_squares(n, o, o) << "\n";
std::cout << "-> sum_of_squares(n, n, n) = " << eve::sum_of_squares(n, n, n) << "\n";
std::cout << "-> sum_of_squares(m, o, o) = " << eve::sum_of_squares(m, o, o)<< "\n";
std::cout << "-> sum_of_squares(m, m, n) = " << eve::sum_of_squares(m, m, n)<< "\n";
std::cout << "-> sum_of_squares(i, n) = " << eve::sum_of_squares(i, n) << "\n";
std::cout << "-> sum_of_squares[pedantic](m, m) = " << eve::sum_of_squares[eve::pedantic](m, m)<< "\n";
std::cout << "-> sum_of_squares[pedantic](m, m, n) = " << eve::sum_of_squares[eve::pedantic](m, m, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](i, n) = " << eve::sum_of_squares[eve::pedantic](i, n) << "\n";
std::cout << "-> sum_of_squares[pedantic](v, v, n) = " << eve::sum_of_squares[eve::pedantic](v, v, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](m, m) = " << eve::sum_of_squares[eve::pedantic](m, m)<< "\n";
std::cout << "-> sum_of_squares(m, m, n) = " << eve::sum_of_squares(m, m, n)<< "\n";
std::cout << "-> sum_of_squares(i, n, n) = " << eve::sum_of_squares(i, n, n) << "\n";
std::cout << "-> sum_of_squares(i, n) = " << eve::sum_of_squares(i, n) << "\n";
std::cout << "-> sum_of_squares(v, v, n) = " << eve::sum_of_squares(v, v, n)<< "\n";
std::cout << "-> sum_of_squares(n, z) = " << eve::sum_of_squares(n, z)<< "\n";
std::cout << "-> sum_of_squares(z, n) = " << eve::sum_of_squares(z, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](n, z) = " << eve::sum_of_squares[eve::pedantic](n, z)<< "\n";
std::cout << "-> sum_of_squares[pedantic](z, n) = " << eve::sum_of_squares[eve::pedantic](z, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](n, n) = " << eve::sum_of_squares[eve::pedantic](n, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](i, n) = " << eve::sum_of_squares[eve::pedantic](n, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](n, i) = " << eve::sum_of_squares[eve::pedantic](n, n)<< "\n";
std::cout << "-> sum_of_squares[pedantic](v, v) = " << eve::sum_of_squares[eve::pedantic](v, v)<< "\n";
}
constexpr auto sqrteps
Computes the square root of the machine epsilon.
Definition sqrteps.hpp:72

◆ trapz

auto eve::trapz = functor<trapz_t>
inlineconstexpr

tuple_callable object applying the trapezoidal composite rule to its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto trapz(eve::non_empty_product_type auto const& x,
eve::non_empty_product_type auto const& y) noexcept; // 1
constexpr auto trapz(floating_value auto ... ys) noexcept; // 2
constexpr auto trapz(eve::non_empty_product_type auto const& y) noexcept; // 2
constexpr auto trapz(floating_value h,
eve::non_empty_product_type auto const& y) noexcept; // 2
constexpr auto trapz(eve::invocable f, floating_value auto ... xs) noexcept; // 3
constexpr auto trapz(eve::invocable f, eve::non_empty_product_type auto const& x) noexcept; // 3
// Semantic options
constexpr auto trapz[widen](/*any of the above overloads*/) noexcept; // 5
constexpr auto trapz[kahan](/*any of the above overloads*/) noexcept; // 6
}

Parameters

  • xs ... : real values ordered arguments in increasing order.
  • x, : tuple of real values ordered arguments in increasing order.
  • y : tuple of real arguments
  • h : floating value scaling the abscissas
  • f : invocable

Return value

  1. Computes elementwise the integral of the piecewise linear function defined by \(f(x_i) = y_i\) (trapezoidal rule)
  2. the missing x parameter is assumed equal to be an arithmetic progression of common difference h (1 if h is omitted).
  3. the missing y parameter is assumed equal to the call of f applied to the x elements
  4. the computation is made with the upgraded types
  5. Internal summation use kahan algorithm for better accuracy
Note
definition of f or of y ?
  • If f is a parameter the y values are defined by \(y_i = \mathrm{f}(x_i)\) and x or xsmust be defined
  • If y (or ys...) is a parameter f is defined by \(f(x_i) = y_i\). and the values of \(x_i\) are not needed as they are equally spaced with space h (defaulted to one).
  • If x (or xs ...) is a parameter its must be sorted in increasing order.

External references

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
{
kumi::tuple tt{0.01,1.01,2.01,3.01,-1.01,-2.01,-3.01,-4.01};
kumi::tuple x{1.0,2.0,3.0,4.0,5.0,6.0,7.0,8.0};
std::cout << " < - x = " << x << std::endl;
std::cout << " < - tt = " << tt << std::endl;
std::cout << " -> trapz(0.01,1.01,2.01,3.01,-1.01,-2.01,-3.01,-4.01) = " << eve::trapz(0.01,1.01,2.01,3.01,-1.01,-2.01,-3.01,-4.01) << std::endl;
std::cout << " -> trapz(tt) = " << eve::trapz(tt) << std::endl;
std::cout << " -> trapz(x, tt) = " << eve::trapz(x, tt) << std::endl;
using w_t = eve::wide<double>;
auto f = [](auto p){return w_t([p](auto q){return p*p+q*3; }); };
auto g = [](auto p){return 2*(p+1); };
w_t h([](auto p){return p+1; });
std::cout << " <- xx = " << xx << std::endl;
std::cout << " <- tt1 = " << tt1 << std::endl;
std::cout << " <- h = " << h << std::endl;
std::cout << " -> trapz(tt1) = " << eve::trapz(tt1) << std::endl;
std::cout << " -> trapz(tt1) = " << eve::trapz(tt1) << std::endl;
std::cout << " -> trapz(2.0, tt1) = " << eve::trapz(2.0, tt1) << std::endl;
std::cout << " -> trapz(h, tt1) = " << eve::trapz(h, tt1) << std::endl;
std::cout << " -> trapz(x tt1) = " << eve::trapz(x, tt1) << std::endl;
std::cout << " -> trapz[widen](x tt1) = " << eve::trapz[eve::widen](x, tt1) << std::endl;
}
}

◆ trunc

auto eve::trunc = functor<trunc_t>
inlineconstexpr

elementwise_callable object computing the integral part of x with the same sign as x.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto trunc(value auto x) noexcept; // 1
// Lanes masking
constexpr auto trunc[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto trunc[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto trunc[almost = tol](floating_value auto x) noexcept; // 3
constexpr auto trunc[almost](floating_value auto x) noexcept; // 4
constexpr auto trunc[raw](floating_value auto x) noexcept; // 5
}
constexpr auto trunc
elementwise_callable object computing the integral part of x with the same sign as x.
Definition trunc.hpp:91

Parameters

Return value

  1. The integral part of x with the same sign as x. The standard proposes 4 rounding modes namely: FE_TONEAREST, FE_DOWNWARD, FE_UPWARD, FE_TOWARDZERO. This function object implements the FE_TOWARDZERO version.
  2. The operation is performed conditionally.
  3. almost allows a fuzzy interpretation of ceil associated to a scalar tolerance.
    • with an integral value tol: computes the ceil of the previous nth representable value in the x type.
    • with a floating value tol: computes the ceil with a tolerance tol.
  4. with no tolerance value, the call is equivalent to ceil[tolerance = 3*eps(as(x))(x)
  5. Faster for floating inputs, but only correct if as an integer, the truncation that can be exactly represented in the associated integral type.

External references

◆ unfold

auto eve::unfold = functor<unfold_t>
inlineconstexpr

tuple_callable utility to convert a pack of values into a tuple of scalar values.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto unfold(eve::value auto ... xs) noexcept; // 1
constexpr auto unfold(non_empty_product_type tup) noexcept; // 2
// Semantic options
constexpr auto unfold[widen](/*any of the above overloads*/) noexcept; // 2
}
constexpr auto unfold
tuple_callable utility to convert a pack of values into a tuple of scalar values.
Definition unfold.hpp:98

Parameters

  • x: value arguments.
  • xs...: values arguments.
  • tup: kumi tuple of values.

Return value

  1. return a kumi tuple of scalar values of the elements of all xs converted to the element type of the common value of the xs.
  2. same as 1., using the tuple elements.
  3. same of 1. or 2., but upgrading the elements of the result.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
constexpr auto S = eve::cardinal_v<eve::wide<float>>;
auto fill = [](auto i, auto){return i;};
auto fill2 = [](auto i, auto){return (i+S);};
auto fill3 = [](auto i, auto){return (i+2*S);};
eve::wide<float> wf(fill);
eve::wide<float> wf2(fill2);
eve::wide<float> wf3(fill3);
std::cout << kumi::cat(eve::unfold(wf), eve::unfold(wf2), eve::unfold(wf3)) << std::endl;
std::cout << eve::unfold(wf, wf2, wf3) << std::endl;
std::cout << eve::unfold[eve::widen](wf, wf2, wf3) << std::endl;
std::cout << eve::unfold[eve::widen](wf, wf2, 1.0f)<< std::endl;
std::cout << eve::unfold(wf, 1.0f, 2.0f) << std::endl;
std::cout << eve::unfold(wi, 1, 2) << std::endl;
auto t = kumi::make_tuple(wi);
std::cout << t << std::endl;
std::cout << eve::unfold(t) << std::endl;
};

◆ variance

auto eve::variance = functor<variance_t>
inlineconstexpr

tuple_callable computing the variance of its arguments.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto variance(eve::floating_value auto ... xs) noexcept; // 1
constexpr auto variance(eve::non_empty_product_type auto const& xs) noexcept; // 2
// Lanes masking
constexpr auto variance[conditional_expr auto c](/* any of the above overloads */) noexcept; // 3
constexpr auto variance[logical_value auto m](/* any of the above overloads */) noexcept; // 3
// Semantic options
constexpr auto variance[raw] (/* any of the above overloads */) noexcept; // 4
constexpr auto variance[widen](/* any of the above overloads */) noexcept; // 5
constexpr auto variance[kahan](/* any of the above overloads */) noexcept; // 6
constexpr auto variance[unbiased](/* any of the above overloads */) noexcept; // 7
}
constexpr auto variance
tuple_callable computing the variance of its arguments.
Definition variance.hpp:111

Parameters

Return value

The value of the variance of the arguments is returned.

  1. the computation of the variance of its arguments.
  2. the computation is made on the tuple values.
  3. The operation is performed conditionally
  4. No provision is made to avoid inaccuracies.
  5. The variance is computed in the double sized element type (if available).
  6. Compensated algorithm for better precision.
  7. the normalizing factor N-1 instead of N to get the best unbiased estimate.
See also
welford_variance for incremental or parallel variance and average computations.

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 << std::setprecision(15);
std::cout << "-> variance(wf0, wf1) = " << eve::variance(wf0, wf1) << "\n";
std::cout << "-> variance(wi0, wi1) = " << eve::variance(wi0, wi1) << "\n";
std::cout << "-> variance[ignore_last(2)](wi0, wi1) = " << eve::variance[eve::ignore_last(2)](wi0, wi1) << "\n";
std::cout << "-> variance[wi0 != 0](wi0, wi1) = " << eve::variance[wi0 != 0](wi0, wi1) << "\n";
std::cout << "-> variance[raw](wi0, wi1) = " << eve::variance[eve::raw](wi0, wi1) << "\n";
auto eps_2 = eve::eps(eve::as<float>())/2;
std::cout << "-> variance(1.0f, eps_2, eps_2, eps_2) = " << eve::variance(1.0f, eps_2, eps_2, eps_2) << "\n";
std::cout << "-> variance[kahan](1.0f, eps_2, eps_2, eps_2) = " << eve::variance[eve::kahan](1.0f, eps_2, eps_2, eps_2) << " // float computation\n";
std::cout << "-> variance[raw](1.0f, eps_2, eps_2, eps_2) = " << eve::variance[eve::raw](1.0f, eps_2, eps_2, eps_2) << "\n";
auto deps_2 = double(eps_2);
std::cout << "-> variance(1.0, deps_2, deps_2, eps_2) = " << float(eve::variance[eve::kahan](1.0, deps_2, deps_2, deps_2)) << " // double computation converted to float\n";
auto tup = kumi::tuple{1.0f, eps_2, eps_2, eps_2};
std::cout << "-> variance[kahan](tup) = " << eve::variance[eve::kahan](tup) << "\n";
std::cout <<eve::variance(1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::raw](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::unbiased](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::unbiased][eve::raw](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
std::cout <<eve::variance[eve::unbiased][eve::raw][eve::widen](1.0f, 2.0f, 3.0f, 4.0f) << "\n";
}

◆ welford_average

auto eve::welford_average = functor<welford_average_t>
inlineconstexpr

tuple_callable computing the arithmetic mean of its arguments with the Welford algorithm, along with the number of elements involved.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto welford_average(auto ... xs) noexcept; //1
constexpr auto welford_average(non_empty_product_type xs) noexcept; //2
//Semantic options
constexpr auto welford_average[widen](/*any previous overload*/) noexcept; //3
}
constexpr auto welford_average
tuple_callable computing the arithmetic mean of its arguments with the Welford algorithm,...
Definition welford_average.hpp:134

Parameters

  • xs...:the parameters can be a mix of floating values and previous results of calls to welford_average

Return value

  1. A struct containing The value of the arithmetic mean and the number of elements on which the mean was calculated is returned.

    This struct is convertible to the average floating value. and possess two fields average and count.

  2. The computation on the tuple elements
  3. The computation and result use the upgraded data type if available
Note
The Welford algorithm does not provides as much option as the average function, but is a quite stable algorithm that have the advantage to allow splitting the computation of the average in multiple calls. For instance: the call with two tuples:
  wavg = welford_average(kumi::cat(xs, ys))
is equivalent to the sequence:
  wxs = welford_average(xs); wys = welford_average(xs); wavg = welford_average(wxs, wys);
But the first two instructions can easily be executed in parallel.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{2.0, 3.0, -1.0, -2.0, -3.0, -4.0, 18.0, 32.0};
using t_t = decltype(wf0);
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
auto ma = eve::welford_average(wf0, 2*wf0, 3*wf0);
auto mb = eve::welford_average(wf1, wf0);
auto mab= eve::average(wf0, 2*wf0, 3*wf0, wf1, wf0);
auto wmab = eve::welford_average(ma, mb);
std::cout << "ma = welford_average(wf0, 2*wf0, 3*wf0) = " << t_t(ma) << std::endl;
std::cout << "mb = welford_average(wf1, wf0) = " << t_t(mb) << std::endl;
std::cout << "eve::average(wf0, 2*wf0, 3*wf0, wf1, wf0) = " << mab << std::endl;
std::cout << "eve::welford_average(ma, mb) = " << t_t(wmab) << std::endl;
}

◆ welford_covariance

auto eve::welford_covariance = functor<welford_covariance_t>
inlineconstexpr

elementwise_callable object computing the elementwise welford_covariance product of the vector of the first half parameter by thevector of the last half.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto welford_covariance(kumi::tuple xs, kumi::tuple ys) noexcept; // 1
constexpr auto welford_covariance(auto wcs...) noexcept; // 2
constexpr auto welford_covariance(kumi;::tuple wcs) noexcept; // 3
// Semantic options
constexpr auto welford_covariance[widen] (/*any of the above overloads*/) noexcept; // 4
constexpr auto welford_covariance[unbiased](/*any of the above overloads*/) noexcept; // 5
}
constexpr auto welford_covariance
elementwise_callable object computing the elementwise welford_covariance product of the vector of the...
Definition welford_covariance.hpp:137

Parameters

  • xs, ys : tuple of values.
  • wcs : arguments or tuple of them. The arguments must all be results of previous welford_covariance calls, Return value
    1. A struct containing The value of the arithmetic means (averagex and averagey ), the centered cross moment of order 2 (mxy), the (sample) covariance value normalized by the number of elements involved (covariance) and the number of elements (count) involved is returned.
      This struct is convertible to the covariance floating value. and possesses four fields averagex, averagey, mxy and count and covariance,that can be output through an std:ostream.
    2. The parameters are composed in a unique covariance struct as if the covariance was computed on the whole original data set. Moreover if only one covariance result simd parameter is present, the lanes individual corariance are grouped in an unique scalar covariance result, computed from all the data of all the lanes.
    3. same as 3. on the tuple elements.
    4. the computation is done in the upgraded element type.
    5. with this option the normalisation is done by the number of elements involved, minus one.
Note
The Welford algorithm does not provides as much option as the covariance function, but is a quite stable algorithm that have the advantage to allow splitting the computation of the covariance in multiple calls. For instance: the call with four tuples:
  cwv = welford_corariance(kumi::cat(xs, ys), kumi::cat(ws, zs))
is equivalent to the sequence:
  cwxs = welford_covariance(xs, ws); cwys = welford_covariance(ys, zs)); cwv = welford_covariance(wxs, wys);
But the first two instructions can easily be executed in parallel.

Example

// revision 0
// revision 0
#include <eve/module/core.hpp>
#include "../../vec3.hpp"
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
// scalar welford_covariance vec3<float>
vec3<float> a(1.0, 2.0, 3.0);
vec3<float> b(-3.0, -4.0, -6.0);
std::cout << "a " << a << std::endl;
std::cout << "b " << b << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](a, b) = "<< eve::welford_covariance[eve::unbiased](a, b) << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](a, a) = " << eve::welford_covariance[eve::unbiased](a, a) << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](b, a) = " << eve::welford_covariance[eve::unbiased](b, a) << std::endl;
std::cout << "eve::welford_covariance[eve::unbiased](b, b) = " << eve::welford_covariance[eve::unbiased](b, b) << std::endl;
// simd welford_covariance eve::wide<vec3<float>, eve::fixed<4>>;
auto wa = wv3_t(a, a, b, b);
auto wb = wv3_t(b, a, a, b);
std::cout << "wa " << wa << std::endl;
std::cout << "wb " << wb << std::endl;
std::cout << "eve::welford_covariance[eve::widen][eve::unbiased](wa, wb) = "<< eve::welford_covariance[eve::widen][eve::unbiased](wa, wb) << std::endl;
kumi::tuple x{4.0f, 3.0f, 2.0f, 1.0f};
kumi::tuple y{1.0f, 2.0f, 3.0f, 4.0f};
std::cout << eve::welford_covariance[eve::unbiased](x, x) << std::endl;
std::cout << eve::welford_covariance[eve::unbiased](x, y) << std::endl;
std::cout << eve::welford_covariance[eve::unbiased](y, x) << std::endl;
}

◆ welford_variance

auto eve::welford_variance = functor<welford_variance_t>
inlineconstexpr

tuple_callable computing the variance of its arguments with the Welford algorithm, along with their average, second centered moment and count.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto welford_variance(auto x, auto ... xs) noexcept; /1
constexpr auto welford_average(non_empty_product_type xs) noexcept; /2
//Semantic options
constexpr auto welford_variance[widen](/*any previous overloads*/) noexcept; /3
constexpr auto welford_variance[unbiased](/*any previous overloads*/) noexcept; /4
}
constexpr auto welford_variance
tuple_callable computing the variance of its arguments with the Welford algorithm,...
Definition welford_variance.hpp:141

Parameters

  • xs:the parameters can be a mix of floating values or previous results of calls to welford_variance or a tuple of them

Return value

  1. A struct containing The value of the arithmetic mean (average), the centered moment of order 2 (m2), the (sample) variance value normalized by the number of elements involved (variance) and the number of elements (count) involved is returned.
    This struct is convertble to the variance floating value. and possess four fields variance, average m2 and count.
  2. The computation is made on the tuples elements
  3. The computation and result use the upgraded data type if available
  4. with this option the normalisation is done by by the number of elements involved, minus one. This provides the best unbiased estimator of the variance (population variance).
Note
The Welford algorithm does not provides as much option as the variance function, but is a quite stable algorithm that have the advantage to allow splitting the computation of the variance in multiple calls. For instance: the call with two tuples:
  wv = welford_corariance(kumi::cat(xs, ys))
is equivalent to the sequence:
  wxs = welford_variance(xs); wys = welford_variance(xs); wv = welford_variance(wxs, wys);
But the first two instructions can easily be executed in parallel.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
#include <tts/tts.hpp>
int main()
{
eve::wide wf0{0.0, 1.0, 2.0, 3.0, -1.0, -2.0, -3.0, -4.0};
eve::wide wf1{2.0, 3.0, -1.0, -2.0, -3.0, -4.0, 18.0, 32.0};
using t_t = decltype(wf0);
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
auto ma = eve::welford_variance(wf0, 2*wf0, 3*wf0);
auto mb = eve::welford_variance(wf1, wf0);
auto mab= eve::welford_variance(wf0, 2*wf0, 3*wf0, wf1, wf0);
auto wmab = eve::welford_variance(ma, mb);
std::cout << "ma = welford_variance(wf0, 2*wf0, 3*wf0) = " << t_t(ma) << std::endl;
std::cout << "mb = welford_variance(wf1, wf0) = " << t_t(mb) << std::endl;
std::cout << "eve::variance(wf0, 2*wf0, 3*wf0, wf1, wf0) = " << mab << std::endl;
std::cout << "eve::welford_variance(ma, mb) = " << t_t(wmab) << std::endl;
auto vw = eve::welford_variance(4.0f, 3.0f, 2.0f, 1.0f);
std::cout << "avg " << vw.average<< std::endl;
std::cout << "var " << vw.variance << std::endl;
std::cout << "s2 " << vw.m2 << std::endl;
std::cout << eve::welford_variance[eve::unbiased](4.0f, 3.0f, 2.0f, 1.0f)<< std::endl;
std::cout << eve::welford_variance(
eve::welford_variance(1.0f, 2.0f),
eve::welford_variance(3.0f, 4.0f))<< std::endl;
std::cout << eve::welford_variance[eve::unbiased](
eve::welford_variance(1.0f, 2.0f),
eve::welford_variance(3.0f, 4.0f))<< std::endl;
}