CKTIS / C
fma — C23 mathematical function
`fma(x, y, z)` from `<math.h>` computes `x*y + z` as if product and sum had unlimited precision, then rounds only once to `double`. `fmaf` and `fmal` provide the same operation for the other floating types.
Version: C23
Syntax
double fma(double x, double y, double z);fma(x, y, z) from <math.h> computes x*y + z as if product and sum had unlimited precision, then rounds only once to double. fmaf and fmal provide the same operation for the other floating types.
The example calls fma(2.0, 3.0, 4.0) and fma(-2.0, 3.0, 1.0). Output 10 -5 confirms multiplication-before-addition; its practical advantage appears in sums, polynomials, and dot products that are sensitive to a second rounding.
A range error can occur when the final result overflows or underflows. Do not assume ordinary x*y+z is automatically contracted to FMA, because that depends on the implementation and options. Annex F specifies domain errors for 0*∞ and for an infinite product added to an infinity of the opposite sign.
Examples
#include <math.h>
#include <stdio.h>
int main(void) { printf("%.0f %.0f\n", fma(2.0, 3.0, 4.0), fma(-2.0, 3.0, 1.0)); return 0; }
Result
10 -5
The example calls `fma(2.0, 3.0, 4.0)` and `fma(-2.0, 3.0, 1.0)`. Output `10 -5` confirms multiplication-before-addition; its practical advantage appears in sums, polynomials, and dot products that are sensitive to a second rounding.