fma

Description

example

X = fma(A, B, C) computes A.*B+C using a fused multiply add approach. Fused multiply add operations round only once, often making the result more accurate than performing a multiplication operation followed by an addition.

Examples

collapse all

This example shows how to use the fma function to calculate $A×B+C$ using a fused multiply add approach.

Define the inputs and use the fma function to compute the multiply add operation.

a = half(10);
b = half(10);
c = half(2);
x = fma(a, b, c)
x =

half

102

Compare the result of the fma function with the two-step approach of computing the product and then the sum.

temp = a * b;
x = temp + c
x =

half

102

Input Arguments

collapse all

Input array, specified as a floating-point scalar, vector, matrix, or multidimensional array. When A and B are matrices, fma performs element-wise multiplication followed by addition.

Data Types: single | double | half

Input array, specified as a floating-point scalar, vector, matrix, or multidimensional array. When A and B are matrices, fma performs element-wise multiplication followed by addition.

Data Types: single | double | half

Input array, specified as a floating-point scalar, vector, matrix, or multidimensional array.

Data Types: single | double | half

Output Arguments

collapse all

Result of multiply and add operation, A.*B+C, returned as a scalar, vector, matrix, or multidimensional array. 