E.V.E  0.1-beta

◆ fnma

eve::fnma = {}
inlineconstexpr

Callable object computing the fused negate-multiply-add operation.

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

Members Functions

Member Effect
operator() the fused negate-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 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.

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

Warning
Note This fnma 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::fnma

Parameters

cond : conditional expression

Return value

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


Supported decorators

  • eve::pedantic

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

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

    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.

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

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

    The expression diff_1st(fnma)(x,y,z), diff_2nd(fnma)(x,y,z) and diff_3rd(fnma)(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/diff/fnma.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'
<< "-> fnma(pf, qf, rf) = " << eve::fnma(pf, qf, rf) << '\n'
<< "-> diff_1st(fnma)(pf, qf, rf) = " << eve::diff_1st(eve::fnma)(pf, qf, rf) << '\n'
<< "-> diff_2nd(fnma)(pf, qf, rf) = " << eve::diff_2nd(eve::fnma)(pf, qf, rf) << '\n'
<< "-> diff_3rd(fnma)(pf, qf, rf) = " << eve::diff_3rd(eve::fnma)(pf, qf, rf) << '\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'
<< "-> diff_1st(fnma)(xf, yf, zf) = " << eve::diff_1st(eve::fnma)(xf, yf, zf) << '\n'
<< "-> diff_2nd(fnma)(xf, yf, zf) = " << eve::diff_2nd(eve::fnma)(xf, yf, zf) << '\n'
<< "-> diff_3rd(fnma)(xf, yf, zf) = " << eve::diff_3rd(eve::fnma)(xf, yf, zf) << '\n';
return 0;
}
constexpr callable_fnma_ fnma
Callable object computing the fused negate-multiply-add operation.
Definition: fnma.hpp:99
constexpr diff_type< 2 > const diff_2nd
Higher-order Callable Object imbuing derivative semantics onto other Callable Objects.
Definition: derivative.hpp:125
constexpr diff_type< 1 > const diff_1st
Higher-order Callable Object imbuing derivative semantics onto other Callable Objects.
Definition: derivative.hpp:92
constexpr diff_type< 3 > const diff_3rd
Higher-order Callable Object imbuing derivative semantics onto other Callable Objects.
Definition: derivative.hpp:158
Wrapper for SIMD registers.
Definition: wide.hpp:65