无涯教程-fma(x,y,z)函数

126 阅读1分钟

该函数计算表达式x * y + z不会在任何中间结果中损失其精度。

假设数字为 x,y和 z :

fma(x,y,z) = x*y+z;

fma - 语法

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: 如果任何参数为long double类型,则返回类型将提升为long double类型。如果不是,则将返回类型提升为双精度。

fma - 参数

x : 要相乘的值。

y : 要乘以x的值。

z : 要与x和y的乘积相加的值。

fma - 返回值

它返回x * y + z的结果。

fma - 例子1

让我们看一个简单的例子。

#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。

参考链接

www.learnfk.com/c++/cpp-mat…