avx2 fma
C ++ fma()函数 (C++ fma() function)
fma() function is a library function of cmath header, it is used to find the result of multiply-add, it accepts three arguments and returns the result of the expression where first and second arguments will be multiplied and the third argument will be added to the multiplied result. It the arguments are x, y and z, it returns (x*y+z).
fma()函数是cmath标头的库函数,用于查找乘加结果,它接受三个参数并返回表达式的结果,其中第一个和第二个参数将相乘,第三个参数将被添加相乘的结果。 如果参数是x , y和z ,则返回(x * y + z) 。
Note: The fma() function computes and returns the exact result without losing precision.
注意: fma()函数计算并返回精确结果,而不会损失精度。
Syntax of fma() function:
fma()函数的语法:
fma(x, y, z);
Parameter(s): x, y, z – are the numbers to calculate the multiply-add.
参数: x,y,z –是用于计算乘加的数字。
Return value: double – it returns double value that is the result of x*y+z.
返回值: double-返回x * y + z的结果double值。
Example:
例:
Input:
float x = 10.20;
float y = 20.91;
float z = 30.12;
Function call:
fma(x, y, z);
Output:
243.402
C ++代码演示fma()函数的示例 (C++ code to demonstrate the example of fma() function)
// C++ code to demonstrate the example of
// fma() function
#include <iostream>
#include <cmath>
using namespace std;
// main() section
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;
}
Output
输出量
result: 5
result: 243.402
result: -243.681
翻译自: https://www.includehelp.com/cpp-tutorial/fma-function-with-example.aspx
avx2 fma