chsvlib
chsv helper source code

◆ fmsub()

constexpr T Chusov::Math::fmsub ( const T &  multiplicand1,
const T &  multiplicand2,
const T &  subtrahend 
)
constexprnoexcept

Generic implementation of fused multiple-subtract.

Template Parameters
TA type that provides for multiplication and subtraction using the respective C++ operators * and -. If T is a standard floating-point type, i.e. float, double or long double, the operation is performed as if the rounding occurred only once after multiplication and subtraction with infinite precision are both complete. Otherwise, ordinary multiplication followed by addition are performed upon the operands. The chsvlib library calls this function using ADL, so other, i. e. for types other than generic T, implementations of fmsub can be used provided they are accessible via ADL.
Parameters
multiplicand1The first (left) multiplicand.
multiplicand2The second (right) multiplicand.
subtrahendThe subtrahend.
Returns
The resulting value.

The generic template function evaluates the result of

multiplicand1 * multiplicand2 - subtrahend

Specializations for standard floating-point types exist and delegate the call to the standard fmaf, fma and fmal functions in order to perform correct rounding of the result.

The functions should be accessed using ADL and are accessed this way from within chsvlib so that custom implementations of FMA can be employed if necessary.

See also
fmadd