Chapter Contents

Previous

Next
fma

fma



Compute floating-point multiply and add functions

Portability: C99


SYNOPSIS
DESCRIPTION
RETURN VALUE
IMPLEMENTATIONS
DIAGNOSTICS
SEE ALSO


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

fma computes x*y+z as if it was a single operation rounded according to the current rounding mode. For binary floating point, the performance of fma will be better than the performance of the equivalent expression, so long as a #undef is not used to undefine fma. For hexadecimal floating point, fma performs considerably worse than the defining expression above. The symbol FP_FAST_FMA can be tested to portably determine if the use of fma is advantageous.

The function name fmaf should be used for float arguments, and fmal for long double arguments. Alternately, if the header file tgmath.h is included, fma may be used with any numeric argument type.


RETURN VALUE

fma returns x*y+z, computed as a single operation, if it is expressible in the return type.


IMPLEMENTATIONS

For binary floating-point, fma is implemented as a built-in function unless it is undefined by a #undef statement.


DIAGNOSTICS

For binary floating point, if the fma function is not undefined, any floating-point exceptions produced during its execution will be raised in the normal fashion, perhaps with trapping. No diagnostic message will be generated, and errno will not be set. If the built-in fma is undefined, overflow or underflow will cause a diagnostic message to be generated, and trapping will not occur.

The error behavior for hexadecimal floating point is the same as for binary when the built-in function is undefined, that is, errors will be diagnosed, and errno will be set.


SEE ALSO

"Mathematical Functions" in Chapter 2, "Function Categories"


Chapter Contents

Previous

Next

Top of Page

Copyright © 2004 by SAS Institute Inc., Cary, NC, USA. All rights reserved.