# fmaf(3) [freebsd man page]

FMA(3) BSD Library Functions Manual FMA(3)NAME

fma, fmaf, fmalfused multiply-add--LIBRARY

Math Library (libm, -lm)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

The fma(), fmaf(), and fmal() functions return (x * y) + z, computed with only one rounding error. Using the ordinary multiplication and addition operators, by contrast, results in two roundings: one for the intermediate product and one for the final result. For instance, the expression 1.2e100 * 2.0e208 - 1.4e308 produces infinity due to overflow in the intermediate product, whereas fma(1.2e100, 2.0e208, -1.4e308) returns approximately 1.0e308. The fused multiply-add operation is often used to improve the accuracy of calculations such as dot products. It may also be used to improve performance on machines that implement it natively. The macros FP_FAST_FMA, FP_FAST_FMAF and FP_FAST_FMAL may be defined in <math.h> to indicate that fma(), fmaf(), and fmal() (respectively) have comparable or faster speed than a multiply operation followed by an add opera- tion.IMPLEMENTATION NOTES

In general, these routines will behave as one would expect if x * y + z were computed with unbounded precision and range, then rounded to the precision of the return type. However, on some platforms, if z is NaN, these functions may not raise an exception even when the computation of x * y would have otherwise generated an invalid exception.SEE ALSO

fenv(3), math(3)STANDARDS

The fma(), fmaf(), and fmal() functions conform to ISO/IEC 9899:1999 (``ISO C99''). A fused multiply-add operation with virtually identical characteristics appears in IEEE draft standard 754R.HISTORY

The fma() and fmaf() routines first appeared in FreeBSD 5.4, and fmal() appeared in FreeBSD 6.0.BSD

January 22, 2005 BSD

## Check Out this Related Man Page

FMA(3) Linux Programmer's Manual FMA(3)NAME

fma, fmaf, fmal - floating-point multiply and addSYNOPSIS

#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); Link withFeature Test Macro Requirements for glibc (see feature_test_macros(7)): fma(), fmaf(), fmal(): _XOPEN_SOURCE >= 600 || _ISOC99_SOURCE; or cc-lm.-std=c99DESCRIPTION

The fma() function computes x * y + z. The result is rounded as one ternary operation according to the current rounding mode (see fenv(3)).RETURN VALUE

These functions return the value of x * y + z, rounded as one ternary operation. If x or y is a NaN, a NaN is returned. If x times y is an exact infinity, and z is an infinity with the opposite sign, a domain error occurs, and a NaN is returned. If one of x or y is an infinity, the other is 0, and z is not a NaN, a domain error occurs, and a NaN is returned. If one of x or y is an infinity, and the other is 0, and z is a NaN, a domain error occurs, and a NaN is returned. If x times y is not an infinity times zero (or vice versa), and z is a NaN, a NaN is returned. If the result overflows, a range error occurs, and an infinity with the correct sign is returned. If the result underflows, a range error occurs, and a signed 0 is returned.ERRORS

See math_error(7) for information on how to determine whether an error has occurred when calling these functions. The following errors can occur: Domain error: x * y + z, or x * y is invalid and z is not a NaN An invalid floating-point exception (FE_INVALID) is raised. Range error: result overflow An overflow floating-point exception (FE_OVERFLOW) is raised. Range error: result underflow An underflow floating-point exception (FE_UNDERFLOW) is raised. These functions do not set errno.VERSIONS

These functions first appeared in glibc in version 2.1.CONFORMING TO

C99, POSIX.1-2001.SEE ALSO

remainder(3), remquo(3)COLOPHON

This page is part of release 3.25 of the Linux man-pages project. A description of the project, and information about reporting bugs, can be found at http://www.kernel.org/doc/man-pages/. 2008-10-06 FMA(3)