1FMA(3P)                    POSIX Programmer's Manual                   FMA(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fma, fmaf, fmal — floating-point multiply-add
13

SYNOPSIS

15       #include <math.h>
16
17       double fma(double x, double y, double z);
18       float fmaf(float x, float y, float z);
19       long double fmal(long double x, long double y, long double z);
20

DESCRIPTION

22       The functionality described on this reference page is aligned with  the
23       ISO C  standard.  Any  conflict between the requirements described here
24       and the ISO C standard is unintentional. This  volume  of  POSIX.1‐2017
25       defers to the ISO C standard.
26
27       These functions shall compute (x * y) + z, rounded as one ternary oper‐
28       ation: they shall compute the value (as if) to infinite  precision  and
29       round once to the result format, according to the rounding mode charac‐
30       terized by the value of FLT_ROUNDS.
31
32       An application wishing to check for error situations should  set  errno
33       to  zero  and  call  feclearexcept(FE_ALL_EXCEPT)  before calling these
34       functions. On return, if errno is non-zero or fetestexcept(FE_INVALID |
35       FE_DIVBYZERO  |  FE_OVERFLOW  | FE_UNDERFLOW) is non-zero, an error has
36       occurred.
37

RETURN VALUE

39       Upon successful completion, these functions shall return  (x * y) +  z,
40       rounded as one ternary operation.
41
42       If  the  result  overflows  or underflows, a range error may occur.  On
43       systems that support the IEC 60559 Floating-Point option, if the result
44       overflows a range error shall occur.
45
46       If x or y are NaN, a NaN shall be returned.
47
48       If x multiplied by y is an exact infinity and z is also an infinity but
49       with the opposite sign, a domain error shall occur, and  either  a  NaN
50       (if supported), or an implementation-defined value shall be returned.
51
52       If one of x and y is infinite, the other is zero, and z is not a NaN, a
53       domain error shall occur, and either a NaN (if supported), or an imple‐
54       mentation-defined value shall be returned.
55
56       If one of x and y is infinite, the other is zero, and z is a NaN, a NaN
57       shall be returned and a domain error may occur.
58
59       If x*y is not 0*Inf nor Inf*0 and z is a NaN, a NaN shall be returned.
60

ERRORS

62       These functions shall fail if:
63
64       Domain Error
65                   The value of x*y+z is invalid, or the value x*y is  invalid
66                   and z is not a NaN.
67
68                   If  the  integer expression (math_errhandling & MATH_ERRNO)
69                   is non-zero, then errno shall be set  to  [EDOM].   If  the
70                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
71                   non-zero, then the invalid floating-point  exception  shall
72                   be raised.
73
74       Range Error The result overflows.
75
76                   If  the  integer expression (math_errhandling & MATH_ERRNO)
77                   is non-zero, then errno shall be set to [ERANGE].   If  the
78                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
79                   non-zero, then the overflow floating-point exception  shall
80                   be raised.
81
82       These functions may fail if:
83
84       Domain Error
85                   The value x*y is invalid and z is a NaN.
86
87                   If  the  integer expression (math_errhandling & MATH_ERRNO)
88                   is non-zero, then errno shall be set  to  [EDOM].   If  the
89                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
90                   non-zero, then the invalid floating-point  exception  shall
91                   be raised.
92
93       Range Error The result underflows.
94
95                   If  the  integer expression (math_errhandling & MATH_ERRNO)
96                   is non-zero, then errno shall be set to [ERANGE].   If  the
97                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
98                   non-zero, then the underflow floating-point exception shall
99                   be raised.
100
101       Range Error The result overflows.
102
103                   If  the  integer expression (math_errhandling & MATH_ERRNO)
104                   is non-zero, then errno shall be set to [ERANGE].   If  the
105                   integer  expression  (math_errhandling & MATH_ERREXCEPT) is
106                   non-zero, then the overflow floating-point exception  shall
107                   be raised.
108
109       The following sections are informative.
110

EXAMPLES

112       None.
113

APPLICATION USAGE

115       On   error,   the   expressions  (math_errhandling  &  MATH_ERRNO)  and
116       (math_errhandling & MATH_ERREXCEPT) are independent of each other,  but
117       at least one of them must be non-zero.
118

RATIONALE

120       In  many  cases,  clever  use of floating (fused) multiply-add leads to
121       much improved code; but its unexpected use by the compiler  can  under‐
122       mine  carefully written code. The FP_CONTRACT macro can be used to dis‐
123       allow use of floating multiply-add; and the fma()  function  guarantees
124       its  use where desired. Many current machines provide hardware floating
125       multiply-add instructions; software implementation can be used for oth‐
126       ers.
127

FUTURE DIRECTIONS

129       None.
130

SEE ALSO

132       feclearexcept(), fetestexcept()
133
134       The Base Definitions volume of POSIX.1‐2017, Section 4.20, Treatment of
135       Error Conditions for Mathematical Functions, <math.h>
136
138       Portions of this text are reprinted and reproduced in  electronic  form
139       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
140       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
141       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
142       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
143       event of any discrepancy between this version and the original IEEE and
144       The Open Group Standard, the original IEEE and The Open Group  Standard
145       is  the  referee document. The original Standard can be obtained online
146       at http://www.opengroup.org/unix/online.html .
147
148       Any typographical or formatting errors that appear  in  this  page  are
149       most likely to have been introduced during the conversion of the source
150       files to man page format. To report such errors,  see  https://www.ker
151       nel.org/doc/man-pages/reporting_bugs.html .
152
153
154
155IEEE/The Open Group                  2017                              FMA(3P)
Impressum