# fma() function in C++

• Last Updated : 26 Sep, 2018

The fma() function takes three arguments a, b and c, and returns a*b+c without losing precision. The fma() function is defined in the cmath header file.
If any argument passed to fma() is long double, the return type is long double. If not, the return type is double.

Syntax:

Want to learn from the best curated videos and practice problems, check out the C++ Foundation Course for Basic to Advanced C++ and C++ STL Course for foundation plus STL.  To complete your preparation from learning a language to DS Algo and many more,  please refer Complete Interview Preparation Course.
```double fma(double a, double b, double c);

or,
long double fma(long double a, long double b, long double c);

or,
float fma(float a, float b, float c)
```

Parameters: This function takes three parameters.

• a: The first argument to be multiplied.
• b: The second argument to be multiplied with a.
• c: The third argument to be added to the product of a and b.

Returns: The fma() function returns a*b+c.

Below programs illustrate the fma() function in C++:

Program 1:

 `// C++ program to demonstrate``// the fma() function`` ` `#include`` ` `using` `namespace` `std;`` ` `int` `main()``{``    ``double` `a = 3.4, b = 2.1, c = 4.2;``    ``double` `ans = fma(a, b, c);``     ` `    ``cout << ``"fma(a, b, c)= "` `<< ans << endl;`` ` `    ``return` `0;``}`
Output:
```fma(a, b, c)= 11.34
```

Program 2:

 `// CPP program to demonstrate``// fma() function`` ` `#include``using` `namespace` `std;`` ` `int` `main()``{``    ``double` `b = 2.1, c = 4.2;``    ``long` `double` `lda = 9.4, answer;``     ` `    ``answer = fma(lda, c, b);``     ` `    ``cout << ``"fma(lda, c, b)="` `<< answer << endl;`` ` `    ``return` `0;``}`
Output:
```fma(lda, c, b)=41.58
```

My Personal Notes arrow_drop_up