E.V.E
v2022.09.01

◆ fms

eve::fms = {}
inlineconstexpr

Computes the fused multiply substract of its three parameters.

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.

Defined in Header

#include <eve/module/core.hpp>

Callable Signatures

namespace eve
{
template< eve::value T >
eve::compatible_value_t fms(T x, U y, V z) noexcept;
}
constexpr callable_fms_ fms
Computes the fused multiply substract of its three parameters.
Definition: fms.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 fms 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'
<< " -> pedantic(fms)(of, pf, qf) = " << eve::pedantic(eve::fms)(of, pf, qf) << '\n'
<< " -> numeric(fms)(of, pf, qf) = " << eve::numeric(eve::fms)(of, pf, qf) << '\n'
<< " -> fms(of, pf, qf) = " << eve::fms(of, pf, qf) << '\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_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::fms[mask](x, ...) provides a masked version of fms which is equivalent to if_else(mask, fms(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'
    << " -> fms[pf < qf](of, pf, qf) = " << eve::fms[pf < qf](of, pf, qf) << '\n';
    return 0;
    }
  • eve::pedantic, eve::numeric
    • The call pedantic(fms)(x,y,z) ensures the one rounding property. This can be very expensive if the system has no hardware capability.
    • 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.
    • see the above regular example.