What is fmal in C?
fmal is a mathematical function in C that multiplies two values together. It then adds a third value and rounds the result, ensuring correct precision while intermediary rounding.
Syntax
long double fmal(
long double x,
long double y,
long double z
);
Parameters
xis the first value to multiply.yis the second value to multiply.zis the value to add.
Return value
The function returns the value of (x*y) + z as calculated to infinite precision and rounded once to adjust according to the result data type.
The following table lists some values on which the function returns other values:
| Input | Returned value |
|---|---|
| x = INFINITY, y = 0 or x = 0, y = INFINITY | NaN |
| x or y = exact ± INFINITY, z = INFINITY with the opposite sign | NaN |
| x or y = NaN | NaN |
| Overflow range error | ±HUGE_VAL, ±HUGE_VALF, or ±HUGE_VALL |
| Underflow range error | correct value, after rounding. |
Example
The following code shows how to use the fmal function in C – we store the result of the computation in fmal_result and print it as a floating point value:
#include<stdio.h>#include <math.h>int main() {double fmal_result = fmal(0.01,10,0.001); //calling the function fmalprintf("fmal(0.01,10,0.001) = %f\n", fmal_result);//}
Free Resources
Copyright ©2025 Educative, Inc. All rights reserved