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

Detailed Description

These functions allows performing exponential computations

Variables

constexpr auto eve::cbrt = functor<cbrt_t>
 elementwise_callable object computing the cubic root.
constexpr auto eve::exp = functor<exp_t>
 elementwise_callable object computing \(e^x\).
constexpr auto eve::exp10 = functor<exp10_t>
 Callable object computing \(10^x\).
constexpr auto eve::exp2 = functor<exp2_t>
 elementwise_callable object computing \(2^x\).
constexpr auto eve::expm1 = functor<expm1_t>
 Callable object computing \(e^x-1\).
constexpr auto eve::expmx2 = functor<expmx2_t>
 elementwise_callable object computing \(e^{-x^2}\).
constexpr auto eve::expx2 = functor<expx2_t>
 Callable object computing \(e^{x^2}\).
constexpr auto eve::geommean = functor<geommean_t>
 Callable object computing the geometric mean of the inputs. \( \left(\prod_{i = 1}^n x_i\right)^{1/n} \).
constexpr auto eve::harmmean = functor<harmmean_t>
 Callable object computing the harmonic mean of the inputs. \( \fracn{\sum \frac1/xs} \).
constexpr auto eve::hypot = functor<hypot_t>
 tuple_callable computing the \(l_2\) norm of its inputs.
constexpr auto eve::kolmmean = functor<kolmmean_t>
 Callable object computing the 'Kolmogorov-Nagumo-de Finetti' mean of the inputs: \( \mathbf{g}(\sum \mathbf{f}(x_s)) \).
constexpr auto eve::lpnorm = functor<lpnorm_t>
 strict_elementwise_callable object computing the lpnorm operation \( \left(\sum_{i = 0}^n |x_i|^p\right)^{\frac1p} \).
constexpr auto eve::nthroot = functor<nthroot_t>
 Callable object computing the nth root: \(x^{1/n}\).
constexpr auto eve::pow = functor<pow_t>
 Callable object computing the pow operation \(x^y\).
constexpr auto eve::pow1p = functor<pow1p_t>
 Callable object computing pow1p: \((1+x)^y\).
constexpr auto eve::pow_abs = functor<pow_abs_t>
 Callable object computing the pow_abs function \(|x|^y\).
constexpr auto eve::powm1 = functor<powm1_t>
 Callable object computing powm1: \(x^y-1\).
constexpr auto eve::significants = functor<significants_t>
 Computes the rounding to n significants digits of the first input.

Variable Documentation

◆ cbrt

auto eve::cbrt = functor<cbrt_t>
inlineconstexpr

elementwise_callable object computing the cubic root.

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto cbrt(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto cbrt[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto cbrt[logical_value auto m](floating_value auto x) noexcept; // 2
}
Specifies that a type is a Conditional Expression.
Definition conditional.hpp:28
The concept floating_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:116
The concept logical_value<T> is satisfied if and only if T satisfies eve::value and the element type ...
Definition value.hpp:134
constexpr auto cbrt
elementwise_callable object computing the cubic root.
Definition cbrt.hpp:69
EVE Main Namespace.
Definition abi.hpp:19

Parameters

Return value

  1. Returns an elementwise cubic root value of the input.
  2. The operation is performed conditionally.

    External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, 1.0f, -1.0f, -2.0f, 8.0f,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> cbrt(wf) = " << eve::cbrt(wf) << "\n";
std::cout << "-> cbrt[ignore_last(2)](wf)= " << eve::cbrt[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> cbrt[wf != -2.0f](wf) = " << eve::cbrt[wf != -2.0f](wf) << "\n";
}
constexpr auto nan
Computes the IEEE quiet NaN constant.
Definition nan.hpp:67
constexpr auto inf
Computes the infinity ieee value.
Definition inf.hpp:67
constexpr auto minf
Computes the -infinity ieee value.
Definition minf.hpp:67
Lightweight type-wrapper.
Definition as.hpp:29
Conditional expression ignoring the k last lanes from a eve::simd_value.
Definition conditional.hpp:361
Wrapper for SIMD registers.
Definition wide.hpp:94

◆ exp

auto eve::exp = functor<exp_t>
inlineconstexpr

elementwise_callable object computing \(e^x\).

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, -0.0f, -1.0f, 1.0f, 2.0f,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> exp(wf) = " << eve::exp(wf) << "\n";
std::cout << "-> exp[raw](wf) = " << eve::exp[eve::raw](wf) << "\n";
std::cout << "-> exp[ignore_last(2)](wf)= " << eve::exp[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> exp[wf != 2.0f](wf) = " << eve::exp[wf != 2.0f](wf) << "\n";
std::cout << eve::exp[eve::raw](1.0) << std::endl;
std::cout << eve::exp[eve::raw](1.0f) << std::endl;
}
constexpr auto raw
Performs the operation minimally, trading accuracy for speed.
Definition core.hpp:95
constexpr auto exp
elementwise_callable object computing .
Definition exp.hpp:89

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto exp(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto exp[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto exp[logical_value auto m](floating_value auto x) noexcept; // 2
constexpr auto exp[raw](floating_value auto x) noexcept; // 3
constexpr auto exp[fast ](floating_value auto x) noexcept; // 3
}
constexpr auto fast
Performs the operation faster than the regular call while keeping more accuracy than raw.
Definition core.hpp:79

Parameters

Return value

  1. Returns the elementwise natural exponential of the input. In particular:
    • If the element is \(\pm0\), \(1\) is returned
    • If the element is \(-\infty\), \(+0\) is returned
    • If the element is \(\infty\), \(\infty\) is returned
    • If the element is a NaN, NaN is returned
  2. The operation is performed conditionally.
  3. The raw and fast options use the very fast and quite inaccurate Schraudolph's algorithm. and the implementation is largely inspired by pmineiro library. raw generally provides around 5%

◆ exp10

auto eve::exp10 = functor<exp10_t>
inlineconstexpr

Callable object computing \(10^x\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto exp10(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto exp10[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto exp10[logical_value auto m](floating_value auto x) noexcept; // 2
}
constexpr auto exp10
Callable object computing .
Definition exp10.hpp:81

Parameters

Return value

  1. Returns the elementwise exponential of base 10 of the input. In particular, for floating inputs:
    • If the element is \(\pm0\), \(1\) is returned
    • If the element is \(-\infty\), \(+0\) is returned
    • If the element is \(\infty\), \(\infty\) is returned
    • If the element is a NaN, NaN is returned

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, -0.0f, -1.0f, 1.0f, 2.0f,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> exp10(wf) = " << eve::exp10(wf) << "\n";
std::cout << "-> exp10[ignore_last(2)](wf)= " << eve::exp10[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> exp10[wf != 2.0f](wf) = " << eve::exp10[wf != 2.0f](wf) << "\n";
}

◆ exp2

auto eve::exp2 = functor<exp2_t>
inlineconstexpr

elementwise_callable object computing \(2^x\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto exp2(value auto x) noexcept; // 1
// Lanes masking
constexpr auto exp2[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto exp2[logical_value auto m](value auto x) noexcept; // 2
}
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 exp2
elementwise_callable object computing .
Definition exp2.hpp:86

Parameters

Return value

  1. Returns the elementwise exponential of base 2 of the input. In particular, for floating inputs:
    • If the element is \(\pm0\), \(1\) is returned
    • If the element is \(-\infty\), \(+0\) is returned
    • If the element is \(\infty\), \(\infty\) is returned
    • If the element is a NaN, NaN is returned
  2. The operation is performed conditionally.
Note
For integral negative entry, the result is zero.

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, -0.0f, -1.0f, 1.0f, 2.0f,
eve::wide<std::int32_t> wi([](auto i, auto c)->std::int32_t{ return i+c/2;});
eve::wide<std::uint32_t> wu([](auto i, auto )->std::uint32_t{ return i;});
std::cout << "<- wf = " << wf << "\n";
// std::cout << "<- wi = " << wi << "\n";
// std::cout << "<- wu = " << wu << "\n";
std::cout << "-> exp2(wf) = " << eve::exp2(wf) << "\n";
std::cout << "-> exp2[raw](wf) = " << eve::exp2[eve::raw](wf) << "\n";
std::cout << "-> exp2(wi) = " << eve::exp2(wi) << "\n";
std::cout << "-> exp2(wu) = " << eve::exp2(wu) << "\n";
std::cout << "-> exp2[ignore_last(2)](wf)= " << eve::exp2[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> exp2[ignore_last(2)](wi)= " << eve::exp2[eve::ignore_last(2)](wi) << "\n";
std::cout << "-> exp2[ignore_last(2)](wu)= " << eve::exp2[eve::ignore_last(2)](wu) << "\n";
std::cout << "-> exp2[wf != 2.0f](wf) = " << eve::exp2[wf != 2.0f](wf) << "\n";
std::cout << "-> exp2[wi != 4](wi) = " << eve::exp2[wi != -2](wi) << "\n";
std::cout << "-> exp2[wu != 2u](wu) = " << eve::exp2[wu != 2u](wu) << "\n";
}

◆ expm1

auto eve::expm1 = functor<expm1_t>
inlineconstexpr

Callable object computing \(e^x-1\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto expm1(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto expm1[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto expm1[logical_value auto m](floating_value auto x) noexcept; // 2
}
constexpr auto expm1
Callable object computing .
Definition expm1.hpp:78

Parameters

Return value

  1. Returns the elementwise exponential of x-1, with good accuracy, even for small values of x. In particular:
    • If the element is \(\pm0\), \(\pm0\) is returned
    • If the element is \(-\infty\), \(-1\) is returned
    • If the element is \(\infty\), \(\infty\) is returned
    • If the element is a NaN, NaN is returned
  2. The operation is performed conditionally

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, -0.0f, -1.0f, 1.0f, 2.0f,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> expm1(wf) = " << eve::expm1(wf) << "\n";
std::cout << "-> expm1[ignore_last(2)](wf)= " << eve::expm1[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> expm1[wf != 2.0f](wf) = " << eve::expm1[wf != 2.0f](wf) << "\n";
}
constexpr auto eps
Computes a constant to the machine epsilon.
Definition eps.hpp:74

◆ expmx2

auto eve::expmx2 = functor<expmx2_t>
inlineconstexpr

elementwise_callable object computing \(e^{-x^2}\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto expmx2(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto expmx2[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto expmx2[logical_value auto m](floating_value auto x) noexcept; // 2
}
constexpr auto expmx2
elementwise_callable object computing .
Definition expmx2.hpp:66

Parameters

Return value

  1. Returns the elementwise exponential of minus the square of x: \(e^{-x^2}\).
  2. The operation is performed conditionally.

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, -0.0f, -1.0f, 1.0f, 2.0f,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> expmx2(wf) = " << eve::expmx2(wf) << "\n";
std::cout << "-> expmx2[ignore_last(2)](wf)= " << eve::expmx2[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> expmx2[wf != 2.0f](wf) = " << eve::expmx2[wf != 2.0f](wf) << "\n";
}

◆ expx2

auto eve::expx2 = functor<expx2_t>
inlineconstexpr

Callable object computing \(e^{x^2}\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto expx2(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto expx2[conditional_expr auto c](floating_value auto x) noexcept; // 2
constexpr auto expx2[logical_value auto m](floating_value auto x) noexcept; // 2
}
constexpr auto expx2
Callable object computing .
Definition expx2.hpp:65

Parameters

Return value

  1. Returns the elementwise exponential of the square of x trying to avoid overflow as possible.
  2. The operation is performed conditionally.

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {0.0f, -0.0f, -1.0f, 1.0f, 2.0f,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> expx2(wf) = " << eve::expx2(wf) << "\n";
std::cout << "-> expx2[ignore_last(2)](wf)= " << eve::expx2[eve::ignore_last(2)](wf) << "\n";
std::cout << "-> expx2[wf != 2.0f](wf) = " << eve::expx2[wf != 2.0f](wf) << "\n";
}

◆ geommean

auto eve::geommean = functor<geommean_t>
inlineconstexpr

Callable object computing the geometric mean of the inputs. \( \left(\prod_{i = 1}^n x_i\right)^{1/n} \).

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide pf = {3.0, -1.0, -3.0, 10.0};
eve::wide qf = {4.0, 1.0, 1.0, 15.0};
eve::wide rf = {-1.0, 2.0, 3.0, 1.5};
kumi::tuple wt{pf, qf, rf};
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "<- rf = " << rf << "\n";
std::cout << "<- wt = " << wt << "\n";
std::cout << "-> geommean(pf, qf) = " << eve::geommean(pf, qf) << "\n";
std::cout << "-> geommean(wt) = " << eve::geommean(wt) << "\n";
std::cout << "-> geommean[ignore_last(2)](pf, qf)= " << eve::geommean[eve::ignore_last(2)](pf, qf) << "\n";
std::cout << "-> geommean[pf > 0.0](pf, qf) = " << eve::geommean[pf > 0.0](pf, qf) << "\n";
std::cout << "-> geommean[pf > 0.0](pf, qf, rf) = " << eve::geommean(pf, qf, rf) << "\n";
auto apf = eve::abs(pf);
auto aqf = eve::abs(qf);
auto arf = eve::abs(rf);
std::cout << "-> geommean(apf, aqf, arf) = " << eve::geommean(apf, aqf, arf) << "\n";
std::cout << "-> geommean[kahan](apf, aqf, arf) = " << eve::geommean[eve::kahan](apf, aqf, arf) << "\n";
std::cout << "-> geommean[pedantic]](apf, aqf, arf) = " << eve::geommean[eve::pedantic](apf, aqf, arf) << "\n";
auto tup = kumi::tuple{apf, aqf, arf};
std::cout << "-> geommean[kahan](tup) = " << eve::geommean[eve::kahan](tup) << "\n";
}
constexpr auto abs
elementwise_callable object computing the absolute value of the parameter.
Definition abs.hpp:86
constexpr auto pedantic
Follows the corner cases of the corresponding standard function.
Definition core.hpp:91
constexpr auto geommean
Callable object computing the geometric mean of the inputs. .
Definition geommean.hpp:92

Header file

#include <eve/module/math.hpp>

Callable Signatures

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

Parameters

Return value

  1. The geometric mean of the inputs is returned
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. uses kahan like compensated algorithm for better accuracy.

External references

◆ harmmean

auto eve::harmmean = functor<harmmean_t>
inlineconstexpr

Callable object computing the harmonic mean of the inputs. \( \fracn{\sum \frac1/xs} \).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto harmmean(floating_value auto ... xs) noexcept; // 1
constexpr auto harmmean(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto harmmean[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto harmmean[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto harmmean[kahan](/*any of the above overloads*/) noexcept; // 4
}
constexpr auto harmmean
Callable object computing the harmonic mean of the inputs. .
Definition harmmean.hpp:91

Parameters

Return value

  1. The harmonic mean of the inputs is returned
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. uses kahan like compensated algorithm for better accuracy.

External references

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide pf = {3.0, -1.0, -3.0, 10.0};
eve::wide qf = {4.0, 1.0, 1.0, 15.0};
eve::wide rf = {-1.0, 2.0, 3.0, 1.5};
kumi::tuple wt{pf, qf, rf};
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "<- rf = " << rf << "\n";
std::cout << "<- wt = " << wt << "\n";
std::cout << "-> harmmean(pf, qf) = " << eve::harmmean(pf, qf) << "\n";
std::cout << "-> harmmean(wt) = " << eve::harmmean(wt) << "\n";
std::cout << "-> harmmean[ignore_last(2)](pf, qf)= " << eve::harmmean[eve::ignore_last(2)](pf, qf) << "\n";
std::cout << "-> harmmean[pf > 0.0](pf, qf) = " << eve::harmmean[pf > 0.0](pf, qf) << "\n";
std::cout << "-> harmmean[pf > 0.0](pf, qf, rf) = " << eve::harmmean(pf, qf, rf) << "\n";
auto tup = kumi::tuple{pf, qf, rf};
std::cout << "<- tup = " << tup << "\n";
std::cout << "-> harmmean[kahan](tup) = " << eve::harmmean[eve::kahan](tup) << "\n";
}

◆ hypot

auto eve::hypot = functor<hypot_t>
inlineconstexpr

tuple_callable computing the \(l_2\) norm of its inputs.

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto hypot(value auto x, value auto ... xs) noexcept; // 1
constexpr auto hypot(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Lanes masking
constexpr auto hypot[conditional_expr auto c](/*any of the above overloads*/) noexcept; // 3
constexpr auto hypot[logical_value auto m](/*any of the above overloads*/) noexcept; // 3
// Semantic options
constexpr auto hypot[raw](/*any of the above overloads*/) noexcept; // 4
constexpr auto hypot[pedantic](/*any of the above overloads*/) noexcept; // 5
constexpr auto hypot[kahan](/*any of the above overloads*/) noexcept; // 6
constexpr auto hypot[widen](/*any of the above overloads*/) noexcept; // 7
}
constexpr auto widen
Computes the result in the upgraded element type.
Definition core.hpp:106
constexpr auto hypot
tuple_callable computing the norm of its inputs.
Definition hypot.hpp:96

Parameters

Return value

  1. Returns \(\displaystyle\sqrt{\sum_1^n |x_i|^2}\). (naive formula) The result type is the common value type of the absolute values of the parameters. (Some appropriate scaling is done to enhance precision and avoid overflows.
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. the naive formula is used.This option is faster, but does not care about avoiding overflows or treating 'Nans' in special ways.
  5. The pedantic option. returns \(\infty\) as soon as after disabling possible Nan parameters the result is \(\infty\), and computes the result without undue overflows or underflows. at intermediate stages of the computation.
  6. A kahan like compensated algorithm is used internal for more accurate results.
  7. The computation is done in the double sized element type (if available).

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
// eve::wide pf = {-1.0, 2.0, -3.0, eve::valmax(eve::as<double>())};
// eve::wide qf = {-4.0, 3.0, -2.0, eve::inf(eve::as<double>())};
// eve::wide rf = {-40.0, 0.03, -2.0, eve::nan(eve::as<double>())};
// kumi::tuple wt{pf, qf};
// std::cout << "<- pf = " << pf << "\n";
// std::cout << "<- qf = " << qf << "\n";
// std::cout << "<- rf = " << rf << "\n";
// std::cout << "<- wt = " << wt << "\n";
// std::cout << "-> hypot(pf,qf) = " << eve::hypot(pf,qf) << "\n";
// std::cout << "-> hypot(wt) = " << eve::hypot(wt) << "\n";
// std::cout << "-> hypot[ignore_last(2)](pf,qf)= " << eve::hypot[eve::ignore_last(2)](pf,qf) << "\n";
// std::cout << "-> hypot[pf > 0.0](pf,qf) = " << eve::hypot[pf > 0.0](pf,qf) << "\n";
// std::cout << "-> hypot[pedantic](pf,qf) = " << eve::hypot[eve::pedantic](pf,qf) << "\n";
// std::cout << "-> hypot(pf,qf,rf) = " << eve::hypot(pf,qf,rf) << "\n";
// std::cout << "-> hypot[pedantic](pf,qf,rf) = " << eve::hypot[eve::pedantic](pf,qf,rf) << "\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 << "-> hypot(i, o, -i) = " << eve::hypot(i, o, -i) << "\n";
std::cout << "-> hypot(i, o, n) = " << eve::hypot(i, o, n) << "\n";
std::cout << "-> hypot[pedantic](i, o, -i) = " << eve::hypot[eve::pedantic](i, o, -i) << "\n";
std::cout << "-> hypot[pedantic](i, o, n) = " << eve::hypot[eve::pedantic](i, o, n) << "\n";
std::cout << "-> hypot[pedantic](o, o, n) = " << eve::hypot[eve::pedantic](o, o, n) << "\n";
std::cout << "-> hypot[pedantic](o, n, o) = " << eve::hypot[eve::pedantic](o, n, o) << "\n";
std::cout << "-> hypot[pedantic](n, o, o) = " << eve::hypot[eve::pedantic](n, o, o) << "\n";
std::cout << "-> hypot (o, o, n) = " << eve::hypot(o, o, n) << "\n";
std::cout << "-> hypot (o, n, o) = " << eve::hypot(o, n, o) << "\n";
std::cout << "-> hypot (n, o, o) = " << eve::hypot(n, o, o) << "\n";
std::cout << "-> hypot(n, n, n) = " << eve::hypot(n, n, n) << "\n";
std::cout << "-> hypot(m, o, o) = " << eve::hypot(m, o, o)<< "\n";
std::cout << "-> hypot(m, m, n) = " << eve::hypot(m, m, n)<< "\n";
std::cout << "-> hypot(i, n) = " << eve::hypot(i, n) << "\n";
std::cout << "-> hypot[pedantic](m, m) = " << eve::hypot[eve::pedantic](m, m)<< "\n";
std::cout << "-> hypot[pedantic](m, m, n) = " << eve::hypot[eve::pedantic](m, m, n)<< "\n";
std::cout << "-> hypot[pedantic](i, n) = " << eve::hypot[eve::pedantic](i, n) << "\n";
std::cout << "-> hypot[pedantic](v, v, n) = " << eve::hypot[eve::pedantic](v, v, n)<< "\n";
std::cout << "-> hypot[pedantic](m, m) = " << eve::hypot[eve::pedantic](m, m)<< "\n";
std::cout << "-> hypot(m, m, n) = " << eve::hypot(m, m, n)<< "\n";
std::cout << "-> hypot(i, n, n) = " << eve::hypot(i, n, n) << "\n";
std::cout << "-> hypot(i, n) = " << eve::hypot(i, n) << "\n";
std::cout << "-> hypot(v, v, n) = " << eve::hypot(v, v, n)<< "\n";
std::cout << "-> hypot(n, z) = " << eve::hypot(n, z)<< "\n";
std::cout << "-> hypot(z, n) = " << eve::hypot(z, n)<< "\n";
std::cout << "-> hypot[pedantic](n, z) = " << eve::hypot[eve::pedantic](n, z)<< "\n";
std::cout << "-> hypot[pedantic](z, n) = " << eve::hypot[eve::pedantic](z, n)<< "\n";
std::cout << "-> hypot[pedantic](n, n) = " << eve::hypot[eve::pedantic](n, n)<< "\n";
std::cout << "-> hypot[pedantic](i, n) = " << eve::hypot[eve::pedantic](n, n)<< "\n";
std::cout << "-> hypot[pedantic](n, i) = " << eve::hypot[eve::pedantic](n, n)<< "\n";
}
constexpr auto valmax
Computes the greatest representable value.
Definition valmax.hpp:67
constexpr auto zero
Computes the constant 0.
Definition zero.hpp:78

◆ kolmmean

auto eve::kolmmean = functor<kolmmean_t>
inlineconstexpr

Callable object computing the 'Kolmogorov-Nagumo-de Finetti' mean of the inputs: \( \mathbf{g}(\sum \mathbf{f}(x_s)) \).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overloads
constexpr auto kolmmean(floating_value auto ... xs) noexcept; // 1
constexpr auto kolmmean(eve::non_empty_product_type auto const& tup) noexcept; // 2
// Semantic options
constexpr auto kolmmean[kahan](/*any of the above overloads*/) noexcept; // 4
}
constexpr auto kolmmean
Callable object computing the 'Kolmogorov-Nagumo-de Finetti' mean of the inputs: .
Definition kolmmean.hpp:91

Parameters

Return value

  1. The kolmogorov mean of the inputs is returned
  2. equivalent to the call on the elements of the tuple.
  3. The operation is performed conditionally
  4. uses kahan like compensated algorithm for better accuracy.
Note
For the result to be a proper kolmogorov mean, f must be mathematically continuous and injective and g be its inverse. and EVE need them to be defined for a floating_value input, and returning the same type. However \( \mathbf{g}(\sum \mathbf{f}(x_s, ...)) \) is returned if computable.

External references

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide pf = {3.0, -1.0, -3.0, 10.0};
eve::wide qf = {4.0, 1.0, 1.0, 15.0};
eve::wide rf = {-1.0, 2.0, 3.0, 1.5};
kumi::tuple wt{pf, qf, rf};
auto f0 = eve::abs; //l1 mean
auto rf0 = f0;
auto f1 = eve::rec[eve::pedantic]; //harmonic
auto rf1 = f1;
auto f2 = [](auto x){ return eve::sqr(x); }; // quadratic
auto rf2 = [](auto x){ return eve::sqrt(x); };
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "<- rf = " << rf << "\n";
std::cout << "<- wt = " << wt << "\n";
std::cout << "-> kolmmean(f0, rf0, pf, qf, rf) = " << eve::kolmmean(f0, rf0, pf, qf, rf) << " //l1 mean\n";
std::cout << "-> kolmmean(f0, rf0, wt) = " << eve::kolmmean(f0, rf0, wt) << "\n";
std::cout << "-> kolmmean(f1, rf1, pf, qf, rf) = " << eve::kolmmean(f1, rf1, pf, qf, rf) << " //harmonic mean\n";
std::cout << "-> kolmmean(f1, rf1, wt) = " << eve::kolmmean(f1, rf1, wt) << "\n";
std::cout << "-> kolmmean(f2, rf2, pf, qf, rf) = " << eve::kolmmean(f2, rf2, pf, qf, rf) << " // quadratic mean\n";
std::cout << "-> kolmmean(f2, rf2, wt) = " << eve::kolmmean(f2, rf2, wt) << "\n\n";
}
constexpr auto sqr
Computes the square of the parameter.
Definition sqr.hpp:98
constexpr auto rec
Computes the inverse of the parameter.
Definition rec.hpp:94
constexpr auto sqrt
Computes the elementwise square root of the parameter.
Definition sqrt.hpp:86

◆ lpnorm

auto eve::lpnorm = functor<lpnorm_t>
inlineconstexpr

strict_elementwise_callable object computing the lpnorm operation \( \left(\sum_{i = 0}^n |x_i|^p\right)^{\frac1p} \).

Defined in Header

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto lpnorm(value auto p, floating_value auto... xs ) noexcept; // 1
constexpr auto lpnorm(value auto p, non_empty_product_type tup) noexcept; // 2
// Lanes masking
constexpr auto lpnorm[conditional_expr auto c](value auto p, floating_value auto... xs) noexcept; // 3
constexpr auto lpnorm[logical_value auto m](value auto p,floating_value auto... xs) noexcept; // 3
// Semantic options
constexpr auto lpnorm[pedantic](/* any of the above overloads */) noexcept; // 4
constexpr auto lpnorm[widen](/* any of the above overloads */) noexcept; // 5
constexpr auto lpnorm[kahan](/* any of the above overloads */) noexcept; // 6
constexpr auto lpnorm[raw](/* any of the above overloads */) noexcept; // 7
}
constexpr auto lpnorm
strict_elementwise_callable object computing the lpnorm operation .
Definition lpnorm.hpp:95

Parameters

Return value

  1. \( \left(\sum_{i = 0}^n |x_i|^p\right)^{\frac1p} \) and \( \max_{i = 0}^n |x_i|} \) if 'p' is infinite.
  2. same as 1. on the tuple elements.
  3. The operation is performed conditionally
  4. returns \(\infty\) as soon as after disabling possible Nan parameters the result is \(\infty\).
  5. The summation is computed in the double sized element type (if available).
  6. Kahan like compensated algorithm is used in internal summation for better precision (see add).
  7. This option is faster, but does not care about avoiding overflows or treating 'Nans' in special ways.

Example

#include <eve/module/math.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <iomanip>
int main()
{
wide_ft x = {eve::nan(eve::as<float>()), 1.0f, 1.0f, 1.0f};
wide_ft y = {-1.5f, 2.9f, 3.5f, -11.0f};
wide_ft z = { eve::inf(eve::as(1.0f)), -2.0f, 1.0f, eve::nan(eve::as<float>())};
wide_ft p = { 3.2f, 3.0f, 2.0f, eve::inf(eve::as(1.0f))};
std::cout << "---- simd" << std::setprecision(5) << '\n'
<< "<- p = " << p << '\n'
<< "<- x = " << x << '\n'
<< "<- y = " << y << '\n'
<< "<- z = " << z << '\n'
<< "-> lpnorm(p, x, y, z) = " << eve::lpnorm(p, x, y, z) << '\n'
<< "-> lpnorm[pedantic](p, x, y, z) = " << eve::lpnorm[eve::pedantic](p, x, y, z) << '\n'
;
double xf = 10.0;
double yf = 1.0;
double zf = 111.0;
double pf = 2.0;
std::cout << "---- scalar" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "<- zf = " << zf << '\n'
<< "-> lpnorm(pf, xf, yf, zf) = " << eve::lpnorm(pf, xf, yf, zf) << '\n'
<< "-> lpnorm[pedantic](pf, xf, yf, zf) = " << eve::lpnorm[eve::pedantic](pf, xf, yf, zf) << '\n';
float o = 1.0f;
float i = eve::inf(eve::as(o));
float n = eve::nan(eve::as(o));
float ma= eve::valmax(eve::as(o));
float m = (ma/3)*2;
std::cout << "<- o = " << o << "\n";
std::cout << "-> i = " << i << "\n";
std::cout << "-> n = " << n << "\n";
std::cout << "-> lpnorm(3, i, o, -i) = " << eve::lpnorm(3, i, o, -i) << "\n";
std::cout << "-> lpnorm(3, i, o, n) = " << eve::lpnorm(3, i, o, n) << "\n";
std::cout << "-> lpnorm[pedantic](3, o, o, n) = " << eve::lpnorm[eve::pedantic](3, o, o, n) << "\n";
std::cout << "-> lpnorm[pedantic](3, o, n, o) = " << eve::lpnorm[eve::pedantic](3, o, n, o) << "\n";
std::cout << "-> lpnorm[pedantic](3, n, o, o) = " << eve::lpnorm[eve::pedantic](3, n, o, o) << "\n";
std::cout << "-> lpnorm[pedantic](3, n, m, m) = " << eve::lpnorm[eve::pedantic](3, n, m, m) << "\n";
std::cout << "-> lpnorm (3, o, o, n) = " << eve::lpnorm(3, o, o, n) << "\n";
std::cout << "-> lpnorm (3, o, n, o) = " << eve::lpnorm(3, o, n, o) << "\n";
std::cout << "-> lpnorm (3, n, o, o) = " << eve::lpnorm(3, n, o, o) << "\n";
std::cout << "-> lpnorm (3, n, m, m) = " << eve::lpnorm(3, n, m, m) << "\n";
std::cout << "-> lpnorm(3, n, n, n) = " << eve::lpnorm(3, n, n, n) << "\n";
std::cout << "-> lpnorm(3, m, o, o) = " << eve::lpnorm(3, m, o, o)<< "\n";
std::cout << "-> lpnorm[pedantic](3, m, o, o) = " << eve::lpnorm[eve::pedantic](3, m, o, o)<< "\n";
std::cout << "-> lpnorm[pedantic](3, i, o, n) = " << eve::lpnorm[eve::pedantic](3, i, o, n) << "\n";
std::cout << "-> lpnorm[pedantic](3, m) = " << eve::lpnorm[eve::pedantic](3, m) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, m) = " << eve::lpnorm[eve::pedantic](3, m, m) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, m, m) = " << eve::lpnorm[eve::pedantic](3, m, m, m) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, m, m, m) = " << eve::lpnorm[eve::pedantic](3, m, m, m, m) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, o, o) = " << eve::lpnorm[eve::pedantic](3, m, o, o)<< "\n";
std::cout << "-> lpnorm(3, i, o, n) = " << eve::lpnorm(3, i, o, n) << "\n";
std::cout << "-> lpnorm(3, m) = " << eve::lpnorm(3, m) << "\n";
std::cout << "-> lpnorm(3, m, m) = " << eve::lpnorm(3, m, m) << "\n";
std::cout << "-> lpnorm(3, m, m, m) = " << eve::lpnorm(3, m, m, m) << "\n";
std::cout << "-> lpnorm(3, m, m, m, m) = " << eve::lpnorm(3, m, m, m, m) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, n) = " << eve::lpnorm[eve::pedantic](3, m, n) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, m, n) = " << eve::lpnorm[eve::pedantic](3, m, m, n) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, m, m, n) = " << eve::lpnorm[eve::pedantic](3, m, m, m, n) << "\n";
std::cout << "-> lpnorm[pedantic](3, m, m, m, m, n) = " << eve::lpnorm[eve::pedantic](3, m, m, m, m, n) << "\n";
std::cout << "-> lpnorm(i, m) = " << eve::lpnorm(i, m) << "\n";
std::cout << "-> lpnorm(i, m, m) = " << eve::lpnorm(i, m, m) << "\n";
std::cout << "-> lpnorm(i, m, m, m) = " << eve::lpnorm(i, m, m, m) << "\n";
std::cout << "-> lpnorm(i, m, m, m, m) = " << eve::lpnorm(i, m, m, m, m) << "\n";
std::cout << "-> lpnorm[pedantic](i, m, n) = " << eve::lpnorm[eve::pedantic](i, m, n) << "\n";
std::cout << "-> lpnorm[pedantic](i, m, m, n) = " << eve::lpnorm[eve::pedantic](i, m, m, n) << "\n";
std::cout << "-> lpnorm[pedantic](i, m, m, m, n) = " << eve::lpnorm[eve::pedantic](i, m, m, m, n) << "\n";
std::cout << "-> lpnorm[pedantic](i, m, m, m, m, n) = " << eve::lpnorm[eve::pedantic](i, m, m, m, m, n) << "\n";
std::cout << "-> lpnorm[raw](3, m) = " << eve::lpnorm[eve::raw](3, m) << "\n";
std::cout << "-> lpnorm[raw](3, m, m) = " << eve::lpnorm[eve::raw](3, m, m) << "\n";
std::cout << "-> lpnorm[raw](3, m, m, m) = " << eve::lpnorm[eve::raw](3, m, m, m) << "\n";
std::cout << "-> lpnorm[raw](3, m, m, m, m) = " << eve::lpnorm[eve::raw](3, m, m, m, m) << "\n";
return 0;
}

◆ nthroot

auto eve::nthroot = functor<nthroot_t>
inlineconstexpr

Callable object computing the nth root: \(x^{1/n}\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto nthroot(floating_value auto x, value auto n) noexcept; noexcept; // 1
// Lanes masking
constexpr auto nthroot[conditional_expr auto c](/* any of the above overloads */) noexcept; // 2
constexpr auto nthroot[logical_value auto m](/* any of the above overloads */) noexcept; // 2
// Semantic options
constexpr auto nthroot[raw](/* any of the above overloads */) noexcept; // 3
}
constexpr auto nthroot
Callable object computing the nth root: .
Definition nthroot.hpp:83

Parameters

Return value

  1. Returns the value of \(x^{1/n}\). For negative x the value returned is a Nan as soon as n is not an odd integer.
  2. The operation is performed conditionally
  3. Speedier but less accurate computation.

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide wf = {2.0f, 64.0f, 4.0f, 2.0f, 2.0f,
eve::wide wn = {4, 3, 2, 1, 0, 4, 3, 2};
std::cout << "<- wf = " << wf << "\n";
std::cout << "<- wn = " << wn << "\n";
std::cout << "-> nthroot(wf, wn) = " << eve::nthroot(wf, wn) << "\n";
std::cout << "-> nthroot[ignore_last(2)](wf, wn)= " << eve::nthroot[eve::ignore_last(2)](wf, wn) << "\n";
std::cout << "-> nthroot[wf != 2.0f](wf, wn) = " << eve::nthroot[wf != 2.0f](wf, wn) << "\n";
std::cout << "-> nthroot[raw](wf, wn) = " << eve::nthroot[eve::raw](wf, wn) << "\n";
}

◆ pow

auto eve::pow = functor<pow_t>
inlineconstexpr

Callable object computing the pow operation \(x^y\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto pow(value auto x, value auto y) noexcept; // 1
// Lanes masking
constexpr auto pow[conditional_expr auto c](value auto x, value auto y) noexcept; // 2
constexpr auto pow[logical_value auto m](value auto x, value auto y) noexcept; // 2
// Semantic options
constexpr auto pow[raw](value auto x, value auto y) noexcept; // 3
constexpr auto pow[mod = p] (floating_value auto x, floating_value auto y) noexcept; // 4
}
constexpr auto pow
Callable object computing the pow operation .
Definition pow.hpp:128

Parameters

Return value

  1. Returns elementwise \(x^y\). In particular we have (IEC 60559):
    • pow(+0, y), where y is a negative odd integer, returns \(+\infty\)
    • pow(-0, y), where y is a negative odd integer, returns \(-\infty\)
    • pow( \(\pm0\), y), where y is negative, finite, and is an even integer or a non-integer, returns \(+\infty\)
    • pow( \(\pm0\), \(-\infty\)) returns \(+\infty\)
    • pow(+0, y), where y is a positive odd integer, returns +0
    • pow(-0, y), where y is a positive odd integer, returns -0
    • pow( \(\pm0\), y), where y is positive non-integer or a positive even integer, returns +0
    • pow(-1, \(\pm\infty\)) returns 1
    • pow(+1, y) returns 1 for any y, even when y is NaN
    • pow(x, \(\pm0\)) returns 1 for any x, even when x is NaN
    • pow(x, y) returns NaN if x is finite and less than 0 and y is finite and non-integer.
    • pow(x, \(-\infty\)) returns \(+\infty\) for any |x|<1
    • pow(x, \(-\infty\)) returns +0 for any |x|>1
    • pow(x, \(+\infty\)) returns +0 for any |x|<1
    • pow(x, \(+\infty\)) returns \(+\infty\) for any |x|>1
    • pow( \(-\infty\), y) returns -0 if y is a negative odd integer
    • pow( \(-\infty\), y) returns +0 if y is a negative non-integer or even integer
    • pow( \(-\infty\), y) returns \(-\infty\) if y is a positive odd integer
    • pow( \(-\infty\), y) returns \(+\infty\) if y is a positive non-integer or even integer
    • pow( \(+\infty\), y) returns +0 for any y less than 0
    • pow( \(+\infty\), y) returns \(+\infty\) for any y greater than 0
    • except where specified above, if any argument is NaN, NaN is returned
  2. The operation is performed conditionally
  3. faster but less accurate call
  4. 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.

External references

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
#include <cmath>
int main()
{
eve::wide qf = {0.0f, 3.0f, -4.0f, 2.0f, 2.0f,
eve::wide pf = {4.0f, 1.0f, -1.0f, 0.5f, 0.0f, 0.0f, -0.0f, 2.5f};
eve::wide pd = {4.0, 1.0, 12.0, 24.0, 13.0, 0.0, 96.0, 2.0};
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "-> pow(pf, qf) = " << eve::pow(pf, qf) << "\n";
std::cout << "-> pow[ignore_last(2)](pf, qf)= " << eve::pow[eve::ignore_last(2)](pf, qf) << "\n";
std::cout << "-> pow[qf > 0.0f](pf, qf) = " << eve::pow[qf > 0.0f](pf, qf) << "\n";
std::cout << "-> pow[raw](pf, qf) = " << eve::pow[eve::raw](pf, qf) << "\n";
std::cout << "<- pd = " << pd << "\n";
std::cout << "<- pow([mod = 97](pd, 96.0) = " << eve::pow[eve::mod = 97](pd, 96.0)<< " //little Fermat\n";
}

◆ pow1p

auto eve::pow1p = functor<pow1p_t>
inlineconstexpr

Callable object computing pow1p: \((1+x)^y\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto pow1p(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto pow1p[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto pow1p[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
// Semantic options
constexpr auto pow1p[raw](floating_value auto x, floating_value auto y) noexcept; // 3
}
constexpr auto pow1p
Callable object computing pow1p: .
Definition pow1p.hpp:80

Parameters

Return value

1. Returns the [elementwise](@ref glossary_elementwise) \f$(1+x)^y\f$, with good accuracy,
   even when `x` is  small.
2. [The operation is performed conditionally](@ref conditional)
3. faster but less accurate call.

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide pf = {2.0f, 3.0f, -4.0f, 2.0f, 2.0f,
eve::wide qf = {4.0f, 1.0f, -1.0f, 0.5f, 0.0f, 2.0f, -3.0f, 2.5f};
std::cout << std::setprecision(10);
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "-> pow1p(pf, qf) = " << eve::pow1p(pf, qf) << "\n";
std::cout << "-> pow1p[ignore_last(2)](pf, qf)= " << eve::pow1p[eve::ignore_last(2)](pf, qf) << "\n";
std::cout << "-> pow1p[qf > 0.0f](pf, qf) = " << eve::pow1p[qf > 0.0f](pf, qf) << "\n";
std::cout << "-> pow1p[raw](pf, qf) = " << eve::pow1p[eve::raw](pf, qf) << "\n";
}

◆ pow_abs

auto eve::pow_abs = functor<pow_abs_t>
inlineconstexpr

Callable object computing the pow_abs function \(|x|^y\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto pow_abs(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto pow_abs[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto pow_abs[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
// Semantic options
constexpr auto pow_abs[raw](floating_value auto x, floating_value auto y) noexcept; // 3
}
constexpr auto pow_abs
Callable object computing the pow_abs function .
Definition pow_abs.hpp:98

Parameters

Return value

Returns elementwise \(|x|^y\).

  1. The result type is the common type of the two parameters. In particular we have (IEC 60559) for floating entries:
    • pow_abs( \(\pm0\), y), where y is a negative odd integer, returns \(+\infty\).
    • pow_abs( \(\pm0\), y), where y is negative, finite, and is an even integer or a non-integer, returns \(+\infty\).
    • pow_abs( \(\pm0\), \(-\infty\)) returns \(+\infty\).
    • pow_abs( \(\pm0\), y), where y is a positive odd integer, returns \(+0\).
    • pow_abs( \(\pm0\), y), where y is positive non-integer or a positive even integer, returns \(+0\).
    • pow_abs(-1, \(\pm\infty\)) returns 1.
    • pow_abs( \(\pm1\), y) returns 1 for any y, even when y is NaN.
    • pow_abs(x, \(\pm0\)) returns 1 for any x, even when x is NaN.
    • pow_abs(x, \(-\infty\)) returns \(+\infty\) for any |x| < 1.
    • pow_abs(x, \(-\infty\)) returns \(+0\) for any |x| > 1.
    • pow_abs(x, \(+\infty\)) returns \(+0\) for any |x| < 1.
    • pow_abs(x, \(+\infty\)) returns \(+\infty\) for any |x| > 1.
    • pow_abs( \(+\infty\), y) returns \(+0\) for any negative y.
    • pow_abs( \(+\infty\), y) returns \(+\infty\) for any positive y.
    • except where specified above, if any argument is NaN, NaN is returned.
  2. The operation is performed conditionally
  3. faster but less accurate call.

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide pf = {2.0f, 3.0f, -4.0f, 2.0f, 2.0f,
eve::wide qf = {4.0f, 1.0f, -1.0f, 0.5f, 0.0f, 2.0f, -3.0f, 2.5f};
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "-> pow_abs(pf, qf) = " << eve::pow_abs(pf, qf) << "\n";
std::cout << "-> pow_abs[ignore_last(2)](pf, qf)= " << eve::pow_abs[eve::ignore_last(2)](pf, qf) << "\n";
std::cout << "-> pow_abs[qf > 0.0f](pf, qf) = " << eve::pow_abs[qf > 0.0f](pf, qf) << "\n";
std::cout << "-> pow_abs[raw](pf, qf) = " << eve::pow_abs[eve::raw](pf, qf) << "\n";
}

◆ powm1

auto eve::powm1 = functor<powm1_t>
inlineconstexpr

Callable object computing powm1: \(x^y-1\).

Header file

#include <eve/module/math.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto powm1(floating_value auto x, floating_value auto y) noexcept; // 1
// Lanes masking
constexpr auto powm1[conditional_expr auto c](floating_value auto x, floating_value auto y) noexcept; // 2
constexpr auto powm1[logical_value auto m](floating_value auto x, floating_value auto y) noexcept; // 2
// Semantic options
constexpr auto powm1[raw](floating_value auto x, floating_value auto y) noexcept; // 3
}
constexpr auto powm1
Callable object computing powm1: .
Definition powm1.hpp:79

Parameters

Return value

  1. Returns the elementwise power minus one, with good accuracy, even when y is very small, or when x is close to 1.
  2. The operation is performed conditionally
  3. faster but less accurate call.

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
int main()
{
eve::wide pf = {2.0f, 3.0f, -4.0f, 2.0f, 2.0f,
eve::wide qf = {4.0f, 1.0f, -1.0f, 0.5f, 0.0f,
eve::eps(eve::as<float>()), -3.0f, 2.5f};
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qf = " << qf << "\n";
std::cout << "-> powm1(pf, qf) = " << eve::powm1(pf, qf) << "\n";
std::cout << "-> powm1[ignore_last(2)](pf, qf)= " << eve::powm1[eve::ignore_last(2)](pf, qf) << "\n";
std::cout << "-> powm1[qf > 0.0f](pf, qf) = " << eve::powm1[qf > 0.0f](pf, qf) << "\n";
std::cout << "-> powm1[raw](pf, qf) = " << eve::powm1[eve::raw](pf, qf) << "\n";
}

◆ significants

auto eve::significants = functor<significants_t>
inlineconstexpr

Computes the rounding to n significants digits of the first input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto significants(auto floating_value x, auto unsigned_value n) noexcept;
}
The concept unsigned_value<T> is satisfied if and only if T satisfies eve::value and the element type...
Definition value.hpp:84
constexpr auto significants
Computes the rounding to n significants digits of the first input.
Definition significants.hpp:66

Parameters

Return value

Computes elementwise the rounding to n significants digits of x. With null n the result is a NaN.

Warning
Floating numbers are not stored in decimal form. So if you try significants with a not exactly representable number the result can be not exactly what you expect.

Example

// revision 1
#include <eve/module/math.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide<std::uint32_t, eve::fixed<8>> qi = {0u, 1u, 2u, 3u, 4u, 5u, 6u, 7u};
float pf = 1.2345678901f;
std::cout << std::setprecision(10);
std::cout << "<- pf = " << pf << "\n";
std::cout << "<- qi = " << qi << "\n";
std::cout << std::setprecision(8);
std::cout << "-> significants(pf, qi)= " << eve::significants(pf, qi) << "\n";
}