E.V.E  0.1-beta

◆ fms

eve::fms = {}
inlineconstexpr

Callable object computing the fused multiply-substract operation.

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

Members Functions

Member Effect
operator() the fused multiply-substract operation
operator[] Construct a conditional version of current function object

template< value T, value U, value V > auto operator()( T x, U y, V z ) const noexcept;
requires compatible< T,U> && compatible< T, V >;

Parameters

x, y, z: values

Return value

The call fms(x, y, z) is similar to x*y-z as if calculated to infinite precision and rounded once to fit the result as much as supported by the hardware.

The result type is the common compatible type of the three parameters.

Warning
Note This fms implementation provides those properties for all integral real value and when possible for floating real value.

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

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

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::pedantic

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

    The call pedantic(fms)(x,y,z) ensures the one rounding property. This can be very expensive if the system has no hardware capability.

  • eve::numeric

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

    The call numeric(fms)(x,y,z) ensures the full compliance to fms properties. This can be very expensive if the system has no hardware capability.

  • eve::diff, eve::diff_1st, eve::diff_2nd, eve::diff_3rd, eve::diff_nth

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

    The expression diff_1st(fms)(x,y,z), diff_2nd(fms)(x,y,z) and diff_3rd(fms)(x,y,z) compute the partial derivatives of \(f\), where \(f\) is the function \((x,y,z) \rightarrow \ xy-z\).

Example

See it live on Compiler Explorer

#include <eve/function/fms.hpp>
#include <eve/function/pedantic/fms.hpp>
#include <eve/function/numeric/fms.hpp>
#include <eve/constant/eps.hpp>
#include <eve/constant/valmax.hpp>
#include <eve/wide.hpp>
#include <iostream>
#include <iomanip>
int main()
{
float es = eve::eps(eve::as<float>());
float esm1 = es-1.0f;
float esp1 = es+1.0f;
float vm = eve::valmax(eve::as<float>());
wide_t oi = {2, -3, esp1, vm};
wide_t pi = {3, -2, esm1, 2 };
wide_t qi = {4, -1, -1.0f, vm};
std::cout << "---- simd" << '\n'
<< " <- oi = " << oi << '\n'
<< " <- pi = " << pi << '\n'
<< " <- qi = " << qi << '\n'
// << " -> pedantic(fms)(oi, pi, qi) = " << eve::pedantic(eve::fms)(oi, pi, qi) << '\n'
// << " -> numeric(fms)(oi, pi, qi) = " << eve::numeric(eve::fms)(oi, pi, qi) << '\n'
<< " -> fms(oi, pi, qi) = " << eve::fms(oi, pi, qi) << '\n'
<< "\n if the last fms result ends by '0, inf}', it is because\n"
<< " the system has no simd fms family intrinsics\n"
<< " or is not configured to use them.\n\n";
std::cout << "---- scalar" << std::setprecision(10) << '\n'
<< " <- vm = " << vm << '\n'
// << " -> pedantic(fms)(vm, 2.0f, vm) = " << eve::pedantic(eve::fms)(vm, 2.0f, -vm) << '\n'
// << " -> numeric(fms)(vm, 2.0f, vm) = " << eve::numeric(eve::fms)(vm, 2.0f, -vm) << '\n'
<< " -> fms(vm, 2.0f, vm) = " << eve::fms(vm, 2.0f, -vm) << '\n'
<< " <- esm1 = " << esm1 << '\n'
<< " <- esp1 = " << esp1 << '\n'
// << " -> pedantic(fms)(esp1, esm1, -1.0f) = " << eve::pedantic(eve::fms)(esp1, esm1, -1.0f) << '\n'
// << " -> numeric(fms)(esp1, esm1, -1.0f) = " << eve::numeric(eve::fms)(esp1, esm1, -1.0f) << '\n'
<< " -> fms(esp1, esm1, -1.0f) = " << eve::fms(esp1, esm1, -1.0f) << '\n';
return 0;
}
constexpr callable_fms_ fms
Callable object computing the fused multiply-substract operation.
Definition: fms.hpp:99
constexpr callable_valmax_ valmax
Callable object computing the greatest representable value.
Definition: valmax.hpp:53
constexpr callable_eps_ eps
Callable object computing the machine epsilon.
Definition: eps.hpp:60
constexpr callable_pi_ pi
Callable object computing the value.
Definition: pi.hpp:54
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65