E.V.E
v2022.09.01

◆ fnma

eve::fnma = {}
inlineconstexpr

Computes the fused negate multiply add of its three parameters.

The call fnma(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 fnma(T x, U y, V z) noexcept;
}
constexpr callable_fnma_ fnma
Computes the fused negate multiply add of its three parameters.
Definition: fnma.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 reasonable cost.

Note
This fnma 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>
int main()
{
wide_ft pf = { 0.0f, 1.0f, -1.0f, -0.5f};
wide_ft qf = { 1.0f, -1.0f, -0.5f, 0.0f};
wide_ft rf = { 1.0f, 2.0f, -5.0f, 0.1f};
std::cout
<< "---- simd" << '\n'
<< "<- pf = " << pf << '\n'
<< "<- qf = " << qf << '\n'
<< "<- rf = " << rf << '\n'
<< " -> pedantic(fnma)(pf, qf, rf) = " << eve::pedantic(eve::fnma)(pf, qf, rf) << '\n'
<< " -> numeric(fnma)(pf, qf, rf) = " << eve::numeric(eve::fnma)(pf, qf, rf) << '\n'
<< " -> fnma(pf, qf, rf) = " << eve::fnma(pf, qf, rf) << '\n'
<< "\n if the last fnma result ends by '0, inf}', it is because\n"
<< " the system has no simd fnma fnmaily intrinsics\n"
<< " or is not configured to use them.\n\n";
float xf = 0.5f;
float yf = 0.5f;
float zf = 0.1f;
std::cout
<< "---- scalar" << '\n'
<< "<- xf = " << xf << '\n'
<< "<- yf = " << yf << '\n'
<< "<- zf = " << yf << '\n'
<< "-> fnma(xf, yf, zf) = " << eve::fnma(xf, yf, zf) << '\n';
return 0;
}
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
Wrapper for SIMD registers.
Definition: wide.hpp:65

Semantic Modifiers

  • Masked Call

    The call eve::fnma[mask](x, ...) provides a masked version of fnma which is equivalent to if_else(mask, fnma(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'
    << " -> fnma[pf < qf](of, pf, qf) = " << eve::fnma[pf < qf](of, pf, qf) << '\n';
    return 0;
    }
    constexpr callable_valmax_ valmax
    Computes the the greatest representable value.
    Definition: valmax.hpp:55
    Lightweight type-wrapper.
    Definition: as.hpp:29
  • eve::pedantic, eve::numeric
    • The call pedantic(fnma)(x,y,z) ensures the one rounding property. This can be very expensive if the system has no hardware capability.
    • The call numeric(fnma)(x,y,z) ensures the full compliance to fnma properties. This can be very expensive if the system has no hardware capability.
    • see the above regular example.