fma、fmaf、fmalfma, fmaf, fmal
9/1/2020
本文內容
將兩個值相乘,並加入第三個值,然後四捨五入結果,而不會因為中繼舍入而遺失任何精確度。Multiplies two values together, adds a third value, and then rounds the result, without losing any precision due to intermediary rounding.
語法Syntax
double fma(
double x,
double y,
double z
);
float fma(
float x,
float y,
float z
); //C++ only
long double fma(
long double x,
long double y,
long double z
); //C++ only
float fmaf(
float x,
float y,
float z
);
long double fmal(
long double x,
long double y,
long double z
);
#define fma(X, Y, Z) // Requires C11 or higher
參數Parameters
Xx
要相乘的第一個值。The first value to multiply.
Yy
要相乘的第二個值。The second value to multiply.
Zz
要加入的值。The value to add.
傳回值Return Value
傳回 (x * y) + z。Returns (x * y) + z. 傳回值接著會使用目前的四捨五入格式來進行四捨五入。The return value is then rounded using the current rounding format.
否則,可能會傳回下列其中一個值:Otherwise, may return one of the following values:
問題Issue
傳回Return
x = 無限大、 y = 0 或x = INFINITY, y = 0 or
x = 0、 y = 無限大x = 0, y = INFINITY
NaNNaN
x 或 y = 精確的±無限大, z = 無限大且正負號相反x or y = exact ± INFINITY, z = INFINITY with the opposite sign
NaNNaN
x 或 y = NaNx or y = NaN
NaNNaN
不 (x = 0、 y= 不定) 和 z = NaNnot (x = 0, y= indefinite) and z = NaN
不 (x= 不定、 y= 0) 和 z = NaNnot (x=indefinite, y=0) and z = NaN
NaNNaN
溢位範圍錯誤Overflow range error
± HUGE_VAL、± HUGE_VALF 或± HUGE_VALL±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL
反向溢位範圍錯誤Underflow range error
四捨五入後的正確值。correct value, after rounding.
依 _matherr 中的指定回報錯誤。Errors are reported as specified in _matherr.
備註Remarks
因為 c + + 允許多載,所以您可以呼叫採用和傳回類型之 fma 的多載 float long double 。Because C++ allows overloading, you can call overloads of fma that take and return float and long double types. 在 C 程式中,除非您使用 宏來呼叫這個函數,否則 fma 一律會採用並傳回 double 。In a C program, unless you're using the macro to call this function, fma always takes and returns a double.
如果您使用 fma() 宏,則引數的類型會決定所選取的函式版本。If you use the fma() macro, the type of the argument determines which version of the function is selected. 如需詳細資料,請參閱 類型-泛型數學 。
此函式會計算值,就像它採用無限精確度,然後將最終結果進行四捨五入。This function computes the value as though it were taken to infinite precision, and then rounds the final result.
依預設,此函式的全域狀態範圍為應用程式。By default, this function's global state is scoped to the application. 若要變更此項,請參閱 CRT 中的全域狀態。
規格需求Requirements
函式Function
C 標頭C header
C++ 標頭C++ header
fma、 fmaf、 fmalfma, fmaf, fmal
fma 宏fma macro
如需其他相容性資訊,請參閱 相容性。For additional compatibility information, see Compatibility.
另請參閱See also