The fmaf
function is defined in the <math.h>
header file in C. It takes in three parameters of type float
: x
, y
, and z
. It then computes and returns the resultant float
value.
The illustration below shows how the fmaf
function works:
The fmaf
function is defined as follows:
float fmaf( float x, float y, float z );
The fmaf
function takes in three parameters of type float
. The first two parameters, x
and y
, are multiplied together. Their product is then added to the third parameter, z
.
The fmaf
function returns the result of the computation of type float
.
The fmaf
function returns special values for certain arguments:
x | y | z | Returned Value |
---|---|---|---|
0 | INFINITY |
Not NaN |
NaN |
INFINITY |
0 | Not NaN |
NAN |
INFINITY |
0 | NaN |
NaN |
0 | INFINITY |
NaN |
NaN |
NaN |
valid float |
valid float |
NaN |
valid float |
NaN |
valid float |
NaN |
valid float |
valid float |
NaN |
NaN |
The following code snippet shows how we can use the fmaf
function:
#include <stdio.h> // include header for printf#include <math.h> // include header for fmafint main(){// setting values fpr x, y, and zfloat x = 2.0;float y = 4.0;float z = 5.0;float result;result = fmaf(x, y, z);printf("The result is: %f", result);return 0;}
The following code snippet shows how error handling in the fmaf
function works:
#include <stdio.h> // include header for printf#include <math.h> // include header for fmafint main(){float x = INFINITY; // setting x to INFINITYfloat y = 0.0;float z = 5.0;float result;result = fmaf(x, y, z);printf("The result is: %f", result);return 0;}
Free Resources