该函数计算表达式x * y + z不会在任何中间结果中损失其精度。
假设数字为 x,y和 z :
fma(x,y,z) = x*y+z;
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);
x : 要相乘的值。
y : 要乘以x的值。
z : 要与x和y的乘积相加的值。
它返回x * y + z的结果。
让我们看一个简单的例子。
#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; }
输出:
Values of x,y,z are :2,3,4 fma(x,y,z) : 10
在此示例中,fma()函数计算x * y + z的结果并返回值10。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)