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

Detailed Description

These functions allows performing some basic arithmetic operations with greater accuracy even when a truly upgraded type is not available.

diff_of_prod, safe_scale, sufp, sulp, sum_of_prod, three_fma, two_add, two_prod, two_sub, veltkamp.

Note
Many functions can also use a widen decorators. This make the whole computation and result made in the upgraded type if available. Currently types with 64 bits elements cannot be upgraded and for then widen has no effect.

Variables

constexpr auto eve::diff_of_prod = functor<diff_of_prod_t>
 elementwise_callable object computing the difference of products operation with better accuracy than the naive formula.
constexpr auto eve::safe_scale = functor<safe_scale_t>
 elementwise_callable object computing underflow-safe and almost overflow-free scaling factor for the input.
constexpr auto eve::sufp = functor<sufp_t>
 elementwise_callable object computing the signed unit value in the first place of the input i.e. the greatest integer power of 2 less than or equal to |x|, multiplied by the sign of x.
constexpr auto eve::sulp = functor<sulp_t>
 elementwise_callable object computing the classical unit in the last place (Kahan) or the harrisson version multiplied by the sign of the input.
constexpr auto eve::sum_of_prod = functor<sum_of_prod_t>
 elementwise_callable object computing the sum of products operation with better accuracy than the naive formula.
constexpr auto eve::three_fma = functor<three_fma_t>
 Computes the elementwise triplet of an fma value f and two errors e1 and e2 such that \(ax+y = f+r_1+r_2\).
constexpr auto eve::two_add = functor<two_add_t>
 Computes the elementwise pair consisting of the sum and its resulting rounding error.
constexpr auto eve::two_div_approx = functor<two_div_approx_t>
 Computes the elementwise pair of division and error,.
constexpr auto eve::two_fma_approx = functor<two_fma_approx_t>
 Computes the elementwise triplet of an fma value f and two errors e1 and e2 such that \(ax+y = f+r_1+r_2\).
constexpr auto eve::two_prod = functor<two_prod_t>
 Computes the elementwise pair of product and error,.
constexpr auto eve::two_sqrt_approx = functor<two_sqrt_approx_t>
 Computes the elementwise pair of square root and error,.
constexpr auto eve::two_sub = functor<two_sub_t>
 Computes the elementwise pair consisting of the difference of the parameters and its resulting rounding error.
constexpr auto eve::veltkamp = functor<veltkamp_t>
 split a loating-point number with radix 2 and p mantissa bits x into two floating-point numbers xh and xl such that, the significand of xh fits in p-floor(p/2), the significand of xl fits in floor(p/2) digits, and x = xh + xl exactly. Where p is the number of mantissa bits of the floating type element.

Variable Documentation

◆ diff_of_prod

auto eve::diff_of_prod = functor<diff_of_prod_t>
inlineconstexpr

elementwise_callable object computing the difference of products operation with better accuracy than the naive formula.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto diff_of_prod(floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 1
// Lanes masking
constexpr auto diff_of_prod[conditional_expr auto c](floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 2
// Semantic exclusive options
constexpr auto diff_of_prod[raw](floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 3
constexpr auto diff_of_prod[pedantic](floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 4
}
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
constexpr auto diff_of_prod
elementwise_callable object computing the difference of products operation with better accuracy than ...
Definition diff_of_prod.hpp:84
constexpr auto raw
Performs the operation minimally, trading accuracy for speed.
Definition core.hpp:95
constexpr auto pedantic
Follows the corner cases of the corresponding standard function.
Definition core.hpp:91
EVE Main Namespace.
Definition abi.hpp:19

Parameters

Return value

  1. The value of x*y-z*t, with better precision if correct fma is available, is returned.
  2. The operation is performed conditionally.
  3. computes a raw version of diff_of_prod, i.e. the naive formula (in fact fms(x, y, z*t))
  4. computes a pedantic version of diff_of_prod ensuring better accuracy in any case.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0 = {3, 2, 1, 0};
eve::wide wf1 = {4, 1, 2, 100};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wf2 = " << wf2 << "\n";
std::cout << "<- wf3 = " << wf3 << "\n";
std::cout << "-> diff_of_prod(wf0, wf1, wf2, wf3) = " << eve::diff_of_prod(wf0, wf1, wf2, wf3) << "\n";
std::cout << "-> diff_of_prod[ignore_last(2)](wf0, wf1, wf2, wf3) = " << eve::diff_of_prod[eve::ignore_last(2)](wf0, wf1, wf2, wf3) << "\n";
std::cout << "-> diff_of_prod[raw](wf0, wf1, wf2, wf3) = " << eve::diff_of_prod[eve::raw](wf0, wf1, wf2, wf3) << "\n";
std::cout << "-> diff_of_prod[pedantic](wf0, wf1, wf2, wf3) = " << eve::diff_of_prod[eve::pedantic](wf0, wf1, wf2, wf3) << "\n";
}
constexpr auto eps
Computes a constant to the machine epsilon.
Definition eps.hpp:74
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

◆ safe_scale

auto eve::safe_scale = functor<safe_scale_t>
inlineconstexpr

elementwise_callable object computing underflow-safe and almost overflow-free scaling factor for the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto safe_scale(floating_value auto x) noexcept; // 1
// Lanes masking
constexpr auto safe_scale[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto safe_scale[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto safe_scale[pedantic](value auto x) noexcept; // 3
}
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 safe_scale
elementwise_callable object computing underflow-safe and almost overflow-free scaling factor for the ...
Definition safe_scale.hpp:84

Parameters

Return value

  1. provide a value s such that |x|/s, is much above the underflow threshold and much below the overflow threshold (so that, for example, we can safely square it); (return maxflint for 0); moreover it is an integer power of 2 (in order to avoid rounding errors when multiplying or dividing by it).
  2. The operation is performed conditionally.
  3. same as 1. but return 1 for 0

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf = { 1.0, 42.0, 1.0e-300, 1.0e300,
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> safe_scale(wf) = " << eve::safe_scale(wf) << "\n";
}
constexpr auto valmax
Computes the greatest representable value.
Definition valmax.hpp:67
constexpr auto smallestposval
Computes the smallest normal positive value.
Definition smallestposval.hpp:71

◆ sufp

auto eve::sufp = functor<sufp_t>
inlineconstexpr

elementwise_callable object computing the signed unit value in the first place of the input i.e. the greatest integer power of 2 less than or equal to |x|, multiplied by the sign of x.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sufp(value auto x) noexcept; // 1
// Lanes masking
constexpr auto sufp[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto sufp[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto sufp[kahan](value auto x) noexcept; // 1
constexpr auto sufp[harrison](value auto x) noexcept; // 3
}
constexpr auto sufp
elementwise_callable object computing the signed unit value in the first place of the input i....
Definition sufp.hpp:84

Parameters

Return value

  1. the signed unit value in the first place of the input. I.e. the greatest integer power of the base (2) less than or equal to |x| multiplied by the sign of x. (Kahan- definition)
    1. The operation is performed conditionally.
    2. The same value up to a factor 2, but with faster computation. (the result is times 2 is the input is not a power of 2).
Note
invalid entries return NaN

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0{0.0, 1.0, 10.0, 100.0, -1.0e8, -2.0e5, -30.0, 10*eve::mindenormal(eve::as(-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 << std::hexfloat << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wi0 = " << wi0 << "\n";
std::cout << "<- wu0 = " << wu0 << "\n";
std::cout << "-> sufp(wf0) = " << eve::sufp(wf0) << "\n";
std::cout << "-> sufp[kahan](wf0) = " << eve::sufp[eve::kahan](wf0) << "\n";
std::cout << "-> sufp[harrisson](wf0) = " << eve::sufp[eve::harrisson](wf0) << "\n";
std::cout << "-> sufp[ignore_last(2)](wf0) = " << eve::sufp[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> sufp[wf0 != 1.0f](wf0) = " << eve::sufp[wf0 != 1](wf0) << "\n";
std::cout << "-> sufp(wu0) = " << eve::sufp(wu0) << "\n";
std::cout << "-> sufp[ignore_last(2)](wu0) = " << eve::sufp[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> sufp[wu0 != 2](wu0) = " << eve::sufp[wu0 != 2](wu0) << "\n";
std::cout << "-> sufp(wi0) = " << eve::sufp(wi0) << "\n";
std::cout << "-> sufp[ignore_last(2)](wi0) = " << eve::sufp[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> sufp[wi0 != 3](wi0) = " << eve::sufp[wi0 != 3](wi0) << "\n";
}
constexpr auto mindenormal
Computes the smallest denormal positive value.
Definition mindenormal.hpp:71

◆ sulp

auto eve::sulp = functor<sulp_t>
inlineconstexpr

elementwise_callable object computing the classical unit in the last place (Kahan) or the harrisson version multiplied by the sign of the input.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sulp(value auto x) noexcept; // 1
// Lanes masking
constexpr auto sulp[conditional_expr auto c](value auto x) noexcept; // 2
constexpr auto sulp[logical_value auto m](value auto x) noexcept; // 2
// Semantic options
constexpr auto sulp[kahan](value auto x) noexcept; // 1
constexpr auto sulp[harrison](value auto x) noexcept; // 3
}
constexpr auto sulp
elementwise_callable object computing the classical unit in the last place (Kahan) or the harrisson v...
Definition sulp.hpp:84

Parameters

Return value

  1. The distance of x to the next representable element in the type of x in the x direction. (Kahan definition)
  2. The operation is performed conditionally.
  3. The distance of x to the nearest representable element in the type of x, not equal to x. (Harrisson definition).
Note
invalid entries return NaN

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, 10*eve::mindenormal(eve::as(-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 << "-> sulp(wf0) = " << eve::sulp(wf0) << "\n";
std::cout << "-> sulp[kahan](wf0) = " << eve::sulp[eve::kahan](wf0) << "\n";
std::cout << "-> sulp[harrisson](wf0) = " << eve::sulp[eve::harrisson](wf0) << "\n";
std::cout << "-> sulp[ignore_last(2)](wf0) = " << eve::sulp[eve::ignore_last(2)](wf0) << "\n";
std::cout << "-> sulp[wf0 != 1.0f](wf0) = " << eve::sulp[wf0 != 1](wf0) << "\n";
std::cout << "-> sulp(wu0) = " << eve::sulp(wu0) << "\n";
std::cout << "-> sulp[ignore_last(2)](wu0) = " << eve::sulp[eve::ignore_last(2)](wu0) << "\n";
std::cout << "-> sulp[wu0 != 2](wu0) = " << eve::sulp[wu0 != 2](wu0) << "\n";
std::cout << "-> sulp(wi0) = " << eve::sulp(wi0) << "\n";
std::cout << "-> sulp[ignore_last(2)](wi0) = " << eve::sulp[eve::ignore_last(2)](wi0) << "\n";
std::cout << "-> sulp[wi0 != 3](wi0) = " << eve::sulp[wi0 != 3](wi0) << "\n";
std::cout << eve::sulp[eve::kahan](wf0)/eve::sulp(wf0) << std::endl;
}

◆ sum_of_prod

auto eve::sum_of_prod = functor<sum_of_prod_t>
inlineconstexpr

elementwise_callable object computing the sum of products operation with better accuracy than the naive formula.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto sum_of_prod(floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 1
// Lanes masking
constexpr auto sum_of_prod[conditional_expr auto c](floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 2
// Semantic exclusive options
constexpr auto sum_of_prod[raw](floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 3
constexpr auto sum_of_prod[pedantic](floating_value auto x, floating_value auto y,
floating_value auto z, floating_value auto t) noexcept; // 4
}
constexpr auto sum_of_prod
elementwise_callable object computing the sum of products operation with better accuracy than the nai...
Definition sum_of_prod.hpp:88

Parameters

Return value

  1. The value of x*y-z*t, with better precision if correct fma is available, is returned.
  2. The operation is performed conditionally.
  3. computes a raw version of sum_of_prod, i.e. the naive formula (in fact fma(x, y, z*t))
  4. computes a pedantic version of diff_of_prod ensuring better accuracy in any case.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0 = {3, 2, 1, 0};
eve::wide wf1 = {4, 1, 2, 100};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wf2 = " << wf2 << "\n";
std::cout << "<- wf3 = " << wf3 << "\n";
std::cout << "-> sum_of_prod(wf0, wf1, wf2, wf3) = " << eve::sum_of_prod(wf0, wf1, wf2, wf3) << "\n";
std::cout << "-> sum_of_prod[ignore_last(2)](wf0, wf1, wf2, wf3) = " << eve::sum_of_prod[eve::ignore_last(2)](wf0, wf1, wf2, wf3) << "\n";
std::cout << "-> sum_of_prod[raw](wf0, wf1, wf2, wf3) = " << eve::sum_of_prod[eve::raw](wf0, wf1, wf2, wf3) << "\n";
std::cout << "-> sum_of_prod[pedantic](wf0, wf1, wf2, wf3) = " << eve::sum_of_prod[eve::pedantic](wf0, wf1, wf2, wf3) << "\n";
}

◆ three_fma

auto eve::three_fma = functor<three_fma_t>
inlineconstexpr

Computes the elementwise triplet of an fma value f and two errors e1 and e2 such that \(ax+y = f+r_1+r_2\).

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto three_fma(floating_value auto a, floating_value auto b, floating_value auto c) noexcept; //1
// Semantic options
constexpr auto three_fma[pedantic](floating_value auto x, floating_value auto y) noexcept; //2
}
constexpr auto three_fma
Computes the elementwise triplet of an fma value f and two errors e1 and e2 such that .
Definition three_fma.hpp:77

Parameters

Return value

  1. Computes elementwise a triplet of values [f, r1, r2] such that:
    • f is fma(a, x, y)
    • \f$ a\otimes x\oplus y = r1\oplus r2\oplus r3\f$ exactly
    • \( |r1 \oplus r2| \le ulp(r1)/2\)
    • \f$ |r2| \le ulp(r2)/2\f$
  2. take care of overflow

where \(\oplus\) (resp. \(\otimes\)) adds (resp. multiplies) its two parameters with infinite precision.

External references

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0 = {30.0, 2.5, -32.7, 1.0};
eve::wide wf1 = {4.2, 1.5, -100.834, eve::eps(eve::as<double>())/2};
eve::wide wf2 = {2.0, 1.234, -2.0, eve::eps(eve::as<double>())/2};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "<- wf2 = " << wf2 << "\n";
std::cout << "-> three_fma(wf0, wf1, wf2) = " << eve::three_fma(wf0, wf1, wf2) << "\n";
using f_t = eve::float16_t;
f_t aa(1000);
auto [a, b, c] = eve::three_fma(aa, aa, -aa);
std::cout << float(a) << " " << float(b) << " " << float(c) << std::endl;
}
IEEE 754 binary16 floating-point type.
Definition float16.hpp:189

◆ two_add

auto eve::two_add = functor<two_add_t>
inlineconstexpr

Computes the elementwise pair consisting of the sum and its resulting rounding error.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto two_add(floating_value auto x, floating_value auto y) noexcept; // 1
constexpr auto two_add[raw](floating_value auto x, floating_value auto y) noexcept; // 2
// Semantic options
constexpr auto two_add[pedantic](floating_value auto x, floating_value auto y) noexcept; // 3
}
constexpr auto two_add
Computes the elementwise pair consisting of the sum and its resulting rounding error.
Definition two_add.hpp:84

Parameters

Return value

Computes elementwise a pair of values [a,e] such that:

  • a is x+y
  • e is a value such that a \(\oplus\)e is equal to x \(\oplus\)y, where \(\oplus\) adds its two parameters with infinite precision.
  1. Classical algorithm, always valid.
  2. 'Fast' algorithm, valid only if |x| < |y|.
  3. Handles overflow.

External references

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0 = {3.0f, 2.5f, -32.7f, 1.0f};
eve::wide wf1 = {4.2f, 1.5f, -100.834f, eve::eps(eve::as<float>())/2};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << std::setprecision(20);
std::cout << "-> two_add(wf0, wf1) = " << eve::two_add(wf0, wf1) << "\n";
std::cout << "-> two_add[raw](wf0, wf1) = " << eve::two_add[eve::raw](wf0, wf1) << "\n";
}

◆ two_div_approx

auto eve::two_div_approx = functor<two_div_approx_t>
inlineconstexpr

Computes the elementwise pair of division and error,.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto two_div_approx(floating_value auto x, floating_value auto y) noexcept;
}
constexpr auto two_div_approx
Computes the elementwise pair of division and error,.
Definition two_div_approx.hpp:70

Parameters

Return value

Computes elementwise a pair of values [a,e] such that:

  • a is x/y
  • e is a value such that a \(\oplus\)e is an approximation in doubled precision to x \(\odiv\)y, where \(\oplus\) (resp. \(\odiv\)) adds (resp. divides) its two parameters with infinite precision.

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0 = {3.0f, 2.5f, -32.7f, 1.0f};
eve::wide wf1 = {4.2f, 1.5f, -100.834f, eve::eps(eve::as<float>())/2};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> two_div_approx(wf0, wf1) = " << eve::two_div_approx(wf0, wf1) << "\n";
auto [d, e] = eve::two_div_approx(1.0f, 3.0f);
std::cout << std::setprecision(15);
std::cout << double(d) << " + " << double(e) << std::endl;
std::cout << double(e)+double(d) << std::endl;
std::cout << 1.0/3.0 << std::endl;
std::cout << 1.0f/3.0f << std::endl;
std::cout << 1.0/3.0 - (double(e)+double(d))<< std::endl;
}

◆ two_fma_approx

auto eve::two_fma_approx = functor<two_fma_approx_t>
inlineconstexpr

Computes the elementwise triplet of an fma value f and two errors e1 and e2 such that \(ax+y = f+r_1+r_2\).

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto two_fma_approx(floating_value auto a, floating_value auto b, floating_value auto c) noexcept;
}
constexpr auto two_fma_approx
Computes the elementwise triplet of an fma value f and two errors e1 and e2 such that .
Definition two_fma_approx.hpp:70

Parameters

Return value

Computes elementwise a pair of values [f, e1] such that:

  • f is fma(a, x, y)
  • \f$ a\otimes x\oplus y = r1\oplus e1\f$ with a very small error (less than 14*eps)

where \(\oplus\) (resp. \(\otimes\)) adds (resp. multiplies) its two parameters with infinite precision.

External references

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide a = {1.0, 2.0, 3.0, 1.0e8};
eve::wide x = {0.1, 0.2, 0.3, 1.0e-8};
eve::wide y = {1.0e-20, 1.0, 2.0, 1.0};
std::cout << std::setprecision(20);
std::cout << "<- a = " << a << "\n";
std::cout << "<- x = " << x << "\n";
std::cout << "<- y = " << y << "\n";
auto [f, e1] = eve::two_fma_approx(a, x, y);
std::cout << "-> f (the fma itself) = " << f << "\n";
std::cout << "-> e1 (the rounding error) = " << e1 << "\n";
}

◆ two_prod

auto eve::two_prod = functor<two_prod_t>
inlineconstexpr

Computes the elementwise pair of product and error,.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto two_prod(floating_value auto x, floating_value auto y) noexcept;
}
constexpr auto two_prod
Computes the elementwise pair of product and error,.
Definition two_prod.hpp:72

Parameters

Return value

Computes elementwise a pair of values [a,e] such that:

  • a is x*y
  • e is a value such that a \(\oplus\)e is equal to x \(\otimes\)y, where \(\oplus\) (resp. \(\otimes\)) adds (resp. multiplies) its two parameters with infinite precision.

External references

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
int main()
{
eve::wide wf0 = {3.0, 2.5, -32.7, 1.0};
eve::wide wf1 = {4.2, 1.5, -100.834, eve::eps(eve::as<double>())/2};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << "-> two_prod(wf0, wf1) = " << eve::two_prod(wf0, wf1) << "\n";
}

◆ two_sqrt_approx

auto eve::two_sqrt_approx = functor<two_sqrt_approx_t>
inlineconstexpr

Computes the elementwise pair of square root and error,.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
constexpr auto two_sqrt_approx(floating_value auto x) noexcept;
}
constexpr auto two_sqrt_approx
Computes the elementwise pair of square root and error,.
Definition two_sqrt_approx.hpp:67

Parameters

Return value

Computes elementwise a pair of values [a,e] such that:

  • a is eve::sqrt(x)
  • e is a value such that a \(\oplus\)e is an approximation in doubled precision to \(\sqrt\)x, where \(\oplus\) (resp. \(\sqrt\)) adds (resp. take the square roots of) its parameters with infinite precision.

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0 = {3.0f, 2.5f, 32.7f, 1.0f};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "-> two_sqrt_approx(wf0) = " << eve::two_sqrt_approx(wf0) << "\n";
auto [d, e] = eve::two_sqrt_approx(3.0f);
std::cout << std::setprecision(15);
std::cout << double(d) << " + " << double(e) << std::endl;
std::cout << double(e)+double(d) << std::endl;
std::cout << eve::sqrt(3.0) << std::endl;
std::cout << eve::sqrt(3.0f) << std::endl;
std::cout << eve::sqrt(3.0) - (double(e)+double(d))<< std::endl;
}
constexpr auto sqrt
Computes the elementwise square root of the parameter.
Definition sqrt.hpp:86

◆ two_sub

auto eve::two_sub = functor<two_sub_t>
inlineconstexpr

Computes the elementwise pair consisting of the difference of the parameters and its resulting rounding error.

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
// Regular overload
constexpr auto two_sub(floating_value auto x, floating_value auto y) noexcept; //1
constexpr auto two_sub[raw](floating_value auto x, floating_value auto y) noexcept; //2
// Semantic options
constexpr auto two_sub[pedantic](floating_value auto x, floating_value auto y) noexcept; //3
}
constexpr auto two_sub
Computes the elementwise pair consisting of the difference of the parameters and its resulting roundi...
Definition two_sub.hpp:80

Parameters

Return value

Computes elementwise a pair of values [a, e] such that:

  • a is x - y
  • e is a value such that a \(\oplus\)e is equal to x \(\oplus\)(-y) where \(\oplus\) adds its two parameters with infinite precision.
  1. Classical algorithm, always valid.
  2. 'Fast' algorithm, valid only if |x| < |y|.
  3. Handles overflow.

External references

Example

// revision 1
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf0 = {3.0f, 2.5f, -32.7f, 1.0f};
eve::wide wf1 = {4.2f, 1.5f, -100.834f, eve::eps(eve::as<float>())/2};
std::cout << "<- wf0 = " << wf0 << "\n";
std::cout << "<- wf1 = " << wf1 << "\n";
std::cout << std::setprecision(20);
std::cout << "-> two_sub(wf0, wf1) = " << eve::two_sub(wf0, wf1) << "\n";
std::cout << "-> two_sub[raw](wf0, wf1) = " << eve::two_sub[eve::raw](wf0, wf1) << "\n";
}

◆ veltkamp

auto eve::veltkamp = functor<veltkamp_t>
inlineconstexpr

split a loating-point number with radix 2 and p mantissa bits x into two floating-point numbers xh and xl such that, the significand of xh fits in p-floor(p/2), the significand of xl fits in floor(p/2) digits, and x = xh + xl exactly. Where p is the number of mantissa bits of the floating type element.

Example

// revision 0
#include <eve/module/core.hpp>
#include <iostream>
#include <iomanip>
int main()
{
eve::wide wf = {1.0, 0.1, 3.14159265358979, 1.0e10};
std::cout << std::setprecision(20);
std::cout << "<- wf = " << wf << "\n";
std::cout << "-> veltkamp(wf) = " << eve::veltkamp(wf) << "\n";
auto [xh, xl] = eve::veltkamp(wf);
std::cout << " xh = " << xh << "\n";
std::cout << " xl = " << xl << "\n";
std::cout << " xh + xl = " << xh + xl << "\n";
}
constexpr auto veltkamp
split a loating-point number with radix 2 and p mantissa bits x into two floating-point numbers xh an...
Definition veltkamp.hpp:70

Header file

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template<eve::floating_value T, eve::floating_value U >
constexpr kumi::tuple<T, T> veltkamp(T x) noexcept;
}

Parameters

Return value

Computes elementwise a pair of values [xh, xl] such that:

  • 'xh+xl' is 'x', but each has much less significant digits.

External references