Implementation status: to be implemented

Synopsis

#include <math.h>

double fma(double x, double y, double z);
float fmaf(float x, float y, float z);
long double fmal(long double x, long double y, long double z);

Description

These functions compute (x * y) + z, rounded as one ternary operation: they compute the value (as if) to infinite precision and round once to the result format, according to the rounding mode characterized by the value of FLT_ROUNDS.

Arguments:
x - the first argument of the function.
y - the second argument of the function.
z - the third argument of the function.

An application wishing to check for error situations should set errno to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these functions. On return, if errno is non-zero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is non-zero, an error has occurred.

Return value

Upon successful completion, these functions return (x * y) + z, rounded as one ternary operation.

If x or y are NaN, a NaN is returned.

If x multiplied by y is an exact infinity and z is also an infinity but with the opposite sign, a domain error occurs, and either a NaN (if supported), or an implementation-defined value is returned.

If one of x and y is infinite, the other is zero, and z is not a NaN, a domain error occurs, and either a NaN (if supported), or an implementation-defined value is returned.

If one of x and y is infinite, the other is zero, and z is a NaN, a NaN is returned and a domain error may occur.

If x * y is not 0 * Inf nor Inf * 0 and z is a NaN, a NaN is returned.

Errors

[ERANGE] The result overflows or underflows.
If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno is set to [ERANGE]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the overflow or underflow floating-point exception is raised.

[EDOM]

  • The value of x * y + z is invalid, or the value x * y is invalid and z is not a NaN.
    If the integer expression (math_errhandling & MATH_ERRNO) is non-zero, then errno is set to [EDOM]. If the integer expression (math_errhandling & MATH_ERREXCEPT) is non-zero, then the invalid floating-point exception is raised.

  • The value x* y is invalid and z is a NaN.

Implementation tasks

  • Implement the fma() function.
  • Implement the fmaf() function.
  • Implement the fmal() function.