E.V.E
v2022.03.00

◆ fma

eve::fma = {}
inlineconstexpr

Computes the fused multiply add of its three parameters.

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.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
eve::compatible_value_t fma(T x, U y, V z) noexcept;
}
constexpr callable_fma_ fma
Computes the fused multiply add of its three parameters.
Definition: fma.hpp:82
Definition: all_of.hpp:22

Parameters

Return value

The value of x*y+z as if calculated to infinite precision and rounded once is returned, but only if the hardware is in capacity to do it at reasonnable cost.

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

Example

#include <eve/module/core.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 of = {2, -3, esp1, vm};
wide_t pf = {3, -2, esm1, 2 };
wide_t qf = {4, -1, 1.0f, -vm};
std::cout << "---- simd" << '\n'
<< " <- of = " << of << '\n'
<< " <- pf = " << pf << '\n'
<< " <- qf = " << qf << '\n'
<< " -> of*pf+qf = " << of*pf+qf << '\n'
<< " -> pedantic(fma)(of, pf, qf) = " << eve::pedantic(eve::fma)(of, pf, qf) << '\n'
<< " -> numeric(fma)(of, pf, qf) = " << eve::numeric(eve::fma)(of, pf, qf) << '\n'
<< " -> fma(of, pf, qf) = " << eve::fma(of, pf, qf) << '\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_valmax_ valmax
Computes the the greatest representable value.
Definition: valmax.hpp:55
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:53
Lightweight type-wrapper.
Definition: as.hpp:29
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

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

    Example

    #include <eve/module/core.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 of = {2, -3, esp1, vm};
    wide_t pf = {3, -2, esm1, 2 };
    wide_t qf = {4, -1, 1.0f, -vm};
    std::cout << "---- simd" << '\n'
    << " <- of = " << of << '\n'
    << " <- pf = " << pf << '\n'
    << " <- qf = " << qf << '\n'
    << " -> fma[pf < qf](of, pf, qf) = " << eve::fma[pf < qf](of, pf, qf) << '\n';
    return 0;
    }
  • eve::pedantic, eve::numeric
    • The call pedantic(fma)(x,y,z) ensures the one rounding property. This can be very expensive if the system has no hardware capability.
    • 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.
    • see the above regular example.