C <math.h> - FP_FAST_FMA, FP_FAST_FMAF, FP_FAST_FMAL
The C <math.h> fma() function returns (x*y) + z. The function computes the result without losing precision and rounded only once to fit the result type.
FP_FAST_FMA, FP_FAST_FMAF and FP_FAST_FMAL macro constants can be defined in an implementation to signal the function to evaluate faster (in addition to being more precise) than the expression (x*y) + z for float, double, and long double arguments, respectively. If defined, these macros evaluate to integer 1.
Macros | Description |
---|---|
FP_FAST_FMA | When defined, function fma() evaluates faster (in addition to being more precise) than the expression (x*y) + z for type double. |
FP_FAST_FMAF | When defined, function fma() evaluates faster (in addition to being more precise) than the expression (x*y) + z for type float. |
FP_FAST_FMAL | When defined, function fma() evaluates faster (in addition to being more precise) than the expression (x*y) + z for type long double. |
Definition in the <math.h> header file is:
#define FP_FAST_FMA /* implementation-defined */ #define FP_FAST_FMAF /* implementation-defined */ #define FP_FAST_FMAL /* implementation-defined */
Example:
The example below shows the usage of these macro constants.
#include <stdio.h> #include <math.h> int main (){ double x, y, z, result; x = 2.1; y = 4.2; z = 10.3; #ifdef FP_FAST_FMA result = fma(x, y, z); #else result = (x * y) + z; #endif printf("(x * y) + z = %f", result); return 0; }
The output of the above code will be:
(x * y) + z = 19.120000
❮ C <math.h> Library