E.V.E  0.1-beta

◆ fma

eve::fma = {}
inlineconstexpr

Callable object computing the fused multiply-add operation.

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

Members Functions

Member Effect
operator() the fused multiply-add 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 fma(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 fma 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::fma

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::pedantic

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

    The call pedantic(fma)(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/fma.hpp>

    The call numeric(fma)(x,y,z) ensures the full compliance to fma 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/fma.hpp>

    The expression diff_1st(fma)(x,y,z), diff_2nd(fma)(x,y,z) and diff_3rd(fma)(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/fma.hpp>
#include <eve/function/pedantic/fma.hpp>
#include <eve/function/numeric/fma.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(fma)(oi, pi, qi) = " << eve::pedantic(eve::fma)(oi, pi, qi) << '\n'
<< " -> numeric(fma)(oi, pi, qi) = " << eve::numeric(eve::fma)(oi, pi, qi) << '\n'
<< " -> fma(oi, pi, qi) = " << eve::fma(oi, pi, qi) << '\n'
<< "\n if the last fma result ends by '0, inf}', it is because\n"
<< " the system has no simd fma family intrinsics\n"
<< " or is not configured to use them.\n\n";
std::cout << "---- scalar" << std::setprecision(10) << '\n'
<< " <- vm = " << vm << '\n'
<< " -> pedantic(fma)(vm, 2.0f, -vm) = " << eve::pedantic(eve::fma)(vm, 2.0f, -vm) << '\n'
<< " -> numeric(fma)(vm, 2.0f, -vm) = " << eve::numeric(eve::fma)(vm, 2.0f, -vm) << '\n'
<< " -> fma(vm, 2.0f, -vm) = " << eve::fma(vm, 2.0f, -vm) << '\n'
<< " <- esm1 = " << esm1 << '\n'
<< " <- esp1 = " << esp1 << '\n'
<< " -> pedantic(fma)(esp1, esm1, 1.0f) = " << eve::pedantic(eve::fma)(esp1, esm1, 1.0f) << '\n'
<< " -> numeric(fma)(esp1, esm1, 1.0f) = " << eve::numeric(eve::fma)(esp1, esm1, 1.0f) << '\n'
<< " -> fma(esp1, esm1, -1.0f) = " << eve::fma(esp1, esm1, 1.0f) << '\n';
return 0;
}
constexpr callable_fma_ fma
Callable object computing the fused multiply-add operation.
Definition: fma.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
constexpr pedantic_type const pedantic
Higher-order Callable Object imbuing more standard semantic onto other Callable Objects.
Definition: pedantic.hpp:56
constexpr numeric_type const numeric
Higher-order Callable Object imbuing non invalid return preference semantic onto other Callable Objec...
Definition: numeric.hpp:52
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65