C++ Math fma
The function computes the expression x*y+z without losing its precision in any intermediate result.
Suppose numbers are x,y and z :
Example
fma(x,y,z) = x*y+z;
Syntax
Example
float fma(float x, float y, float z);
double fma(double x, double y, double z);
long double fma(long double x, long double y, long double z);
double fma(type1 x,type2 y,type3 z);
Note: If any argument is long double type, then the return type is promoted to long double. If not, then the return type is promoted to double.
Parameter
x : The value which is to be multiplied.
y : The value which is to be multiplied with x.
z : The value which is to be added with the product of x and y.
Return value
It returns the result of x*y+z.
Example 1
Let's see the simple example.
Example
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
int x= 2;
int y=3;
int z=4;
std::cout << "Values of x,y,z are :" <<x<<","<<y<<","<<z<< std::endl;
cout<<"fma(x,y,z) : "<<fma(x,y,z);
return 0;
}
Output:
Output
Values of x,y,z are :2,3,4
fma(x,y,z) : 10
In this example, fma function computes the result of x*y+z and returns the value 10.