📅  最后修改于: 2020-09-25 07:38:19             🧑  作者: Mango
此函数在
double fma(double x, double y, double z);
float fma(float x, float y, float z);
long double fma(long double x, long double y, long double z);
Promoted fma(Type1 x, Type2 y, Type z); // For combinations of arithmetic types
从C++ 11开始,如果传递给fma()的任何参数为long double
,则返回类型Promoted
为long double
。如果不是,则返回类型Promoted
为double
。
[Mathematics] x*y+z = fma(x, y, z) [C++ Programming]
fma()接受三个参数。
fma() 函数将返回x*y+z
,就好像计算为无限精度,并四舍五入一次以适合结果类型。
#include
using namespace std;
int main()
{
double x = 2.0, y = 3.1, z = 3.0, result;
result = fma(x, y, z);
cout << "fma(x, y, z) = " << result << endl;
long double xLD = 3.4, resultLD;
resultLD = fma(xLD, y, z);
cout << "fma(xLD, y, z) = " << resultLD << endl;
return 0;
}
运行该程序时,输出为:
fma(x, y, z) = 9.2
fma(xLD, y, z) = 13.54