fma()函数fma()函数是cmath标头的库函数,用于查找乘加结果,它接受三个参数并返回表达式的结果,其中第一个和第二个参数将相乘,第三个参数将被添加相乘的结果。如果参数是x,y和z,则返回(x * y + z)。
注:该FMA()函数计算并返回不失精准确切的结果。
fma()函数语法:
fma(x, y, z);
参数: x,y,z –是用于计算乘加的数字。
返回值: double-它返回作为x * y + z结果的double值。
示例
Input: float x = 10.20; float y = 20.91; float z = 30.12; Function call: fma(x, y, z); Output: 243.402
fma()函数示例//示例
// fma()功能
#include <iostream>
#include <cmath>
using namespace std;
// main()部分
int main(){
float x,y,z;
float result;
x = 1;
y = 2;
z = 3;
result = fma(x,y,z);
cout<<"result: "<<result<<endl;
x = 10.20;
y = 20.91;
z = 30.12;
result = fma(x,y,z);
cout<<"result: "<<result<<endl;
x = -10.21220;
y = 20.9122;
z = -30.1212;
result = fma(x,y,z);
cout<<"result: "<<result<<endl;
return 0;
}输出结果
result: 5 result: 243.402 result: -243.681