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:
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<bits/stdc++.h> 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; } |
fma(a, b, c)= 11.34
Program 2:
// CPP program to demonstrate // fma() function #include<bits/stdc++.h> 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; } |
fma(lda, c, b)=41.58
Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.
Recommended Posts:
- Difference between user defined function and library function in C/C++
- Function Overloading vs Function Overriding in C++
- How to call some function before main() function in C++?
- How to call function within function in C or C++
- Difference between Virtual function and Pure virtual function in C++
- What happens when a virtual function is called inside a non-virtual function in C++
- div() function in C++
- exp() function C++
- log() function in C++
- mbsinit() Function in C/C++
- bit_and function in C++
- mbrlen() function in C/C++
- wcspbrk() function in C/C++
- wcsrchr() function in C/C++
- mbrtowc() function in C/C++
- wcsncat() function in C/C++
- wcsncmp() function in C/C++
- wcsrtombs() function in C/C++
- wcstoul() function in C/C++
- wcstod() function in C/C++
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.

