Math Fma Function - C++ Programming Tutorial
C++ Course / Math Functions / Math Fma Function

Math Fma Function

BLUF: Mastering Math Fma Function is a critical step in becoming a proficient C++ developer. This lesson provides a deep dive into the syntax, performance considerations, and real-world applications of this concept.
Key Performance Insight: Math Fma Function

C++ is renowned for its efficiency. Learn how Math Fma Function enables low-level control and high-performance computing in the tutorial below.

C++ Math fma

The function calculates the expression x multiplied by y, added to z, while maintaining precision throughout all intermediate calculations.

Suppose numbers are x,y and z :

Example

fma(x,y,z) = x*y+z;

Syntax

Example

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);

Note: If any argument is long double type, then the return type is promoted to long double. If not, then the return type is promoted to double.

Parameter

x : The value which is to be multiplied.

y : The value which is to be multiplied with x.

z : The value to be added to the result of multiplying x and y.

Return value

It returns the result of x*y+z.

Example 1

Let's see the simple example.

Example

#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;
}

Output:

Output

Values of x,y,z are :2,3,4
fma(x,y,z) : 10

In this instance, the fma function calculates the outcome of x multiplied by y, added to z, and yields the value of 10.

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience