What is fma() in C?

The fma() (“fused multiply-add”) function is used to compute the following expression:

fma() computes the expression (ab+c)(a * b + c) to infinite precision by computing the expression as a single ternary operation. The expression result is rounded off only once upto the decimal places that can fit in the output data type.

Library

To use the fma() function, include the following library:

#include <math.h>

Syntax

The declaration of the fma() function is shown below:

double fma (double a, double b, double c);

The fma() function computes the expression (a * b + c) on its input parameters and returns the result of the expression.

Code

Consider the code snippet below, which uses fma() to compute ( a * b + c):

#include <stdio.h>
#include <math.h>
int main() {
double a = 1.556532;
double b = 2.389987;
double c = 0.147897;
double x = fma(a, b, c);
printf("fma ( %f, %f, %f ) = ( %lf ) \n", a, b, c, x);
return 0;
}

Explanation

The fma() function is used in line 10 to compute the expression (a * b + c) on variables a, b, and c that are created in lines 5-8.

New on Educative
Learn to Code
Learn any Language as a beginner
Develop a human edge in an AI powered world and learn to code with AI from our beginner friendly catalog
🏆 Leaderboard
Daily Coding Challenge
Solve a new coding challenge every day and climb the leaderboard

Free Resources

Copyright ©2025 Educative, Inc. All rights reserved