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.
long double fmal(
long double x,
long double y,
long double z
);
x
is the first value to multiply.y
is the second value to multiply.z
is the value to add.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. |
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