該函數計算表達式 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);
注意:如果任何參數是 long double 類型,則返回類型將提升為 long double。如果不是,則返回類型被提升為 double。
參數
x:要相乘的值。
y: 與 x 相乘的值。
z: 與 x 和 y 的乘積相加的值。
返回值
它返回 x*y+z 的結果。
例子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。
相關用法
- C++ Math fmax()用法及代碼示例
- C++ Math fmin()用法及代碼示例
- C++ Math fmod()用法及代碼示例
- C++ Math fabs()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math fpclassify()用法及代碼示例
- C++ Math frexp()用法及代碼示例
- C++ Math floor()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math fma()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。