fma, fmaf, fmal, and fmad128 Subroutines

Purpose

Floating-point multiply-add.

Syntax

#include <math.h>

double fma (x, y, z)
double x;
double y;
double z;

float fmaf (x, y, z)
float x;
float y;
float z;

long double fmal (x, y, z)
long double x;
long double y;
long double z;

_Decimal128 fmad128 (x, y, z)
_Decimal128 x;
_Decimal128 y;
_Decimal128 z;

Description

The fma, fmaf, fmal, and fmad128 subroutines 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.

An application wishing to check for error situations should set the errno global variable to zero and call feclearexcept(FE_ALL_EXCEPT) before calling these subroutines. Upon return, if errno is nonzero or fetestexcept(FE_INVALID | FE_DIVBYZERO | FE_OVERFLOW | FE_UNDERFLOW) is nonzero, an error has occurred.

Parameters

Item Description
x Specifies the value to be multiplied by the y parameter.
y Specifies the value to be multiplied by the x parameter.
z Specifies the value to be added to the product of the x and y parameters.

Return Values

Upon successful completion, the fma, fmaf, fmal, and fmad128 subroutines 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 a NaN is returned.

If one of the x and y parameters is infinite, the other is zero, and the z parameter is not a NaN, a domain error occurs, and a NaN is returned.

If one of the x and y parameters 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.