The fma()
(“fused multiply-add”) function is used to compute the following expression:
fma()
computes the expression to infinite precision by computing the expression as a single ternary operation. The expression result is rounded off only once upto the decimal places that can fit in the output data type.
To use the fma()
function, include the following library:
#include <math.h>
The declaration of the fma()
function is shown below:
double fma (double a, double b, double c);
The fma()
function computes the expression (a
* b
+ c
) on its input parameters and returns the result of the expression.
Consider the code snippet below, which uses fma()
to compute ( a
* b
+ c
):
#include <stdio.h>#include <math.h>int main() {double a = 1.556532;double b = 2.389987;double c = 0.147897;double x = fma(a, b, c);printf("fma ( %f, %f, %f ) = ( %lf ) \n", a, b, c, x);return 0;}
The fma()
function is used in line 10
to compute the expression (a
* b
+ c
) on variables a
, b
, and c
that are created in lines 5-8
.
Free Resources