| 1 |
'\" t |
| 2 |
.\" Copyright 2002, Walter Harms <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: GPL-1.0-or-later |
| 6 |
.\" |
| 7 |
.TH fma 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
fma, fmaf, fmal \- floating-point multiply and add |
| 10 |
.SH LIBRARY |
| 11 |
Math library |
| 12 |
.RI ( libm ,\~ \-lm ) |
| 13 |
.SH SYNOPSIS |
| 14 |
.nf |
| 15 |
.B #include <math.h> |
| 16 |
.P |
| 17 |
.BI "double fma(double " x ", double " y ", double " z ); |
| 18 |
.BI "float fmaf(float " x ", float " y ", float " z ); |
| 19 |
.BI "long double fmal(long double " x ", long double " y ", long double " z ); |
| 20 |
.fi |
| 21 |
.P |
| 22 |
.RS -4 |
| 23 |
Feature Test Macro Requirements for glibc (see |
| 24 |
.BR feature_test_macros (7)): |
| 25 |
.RE |
| 26 |
.P |
| 27 |
.BR fma (), |
| 28 |
.BR fmaf (), |
| 29 |
.BR fmal (): |
| 30 |
.nf |
| 31 |
_ISOC99_SOURCE || _POSIX_C_SOURCE >= 200112L |
| 32 |
.fi |
| 33 |
.SH DESCRIPTION |
| 34 |
These functions compute |
| 35 |
.IR x " * " y " + " z . |
| 36 |
The result is rounded as one ternary operation according to the |
| 37 |
current rounding mode (see |
| 38 |
.BR fenv (3)). |
| 39 |
.SH RETURN VALUE |
| 40 |
These functions return the value of |
| 41 |
.IR x " * " y " + " z , |
| 42 |
rounded as one ternary operation. |
| 43 |
.P |
| 44 |
If |
| 45 |
.I x |
| 46 |
or |
| 47 |
.I y |
| 48 |
is a NaN, a NaN is returned. |
| 49 |
.P |
| 50 |
If |
| 51 |
.I x |
| 52 |
times |
| 53 |
.I y |
| 54 |
is an exact infinity, and |
| 55 |
.I z |
| 56 |
is an infinity with the opposite sign, |
| 57 |
a domain error occurs, |
| 58 |
and a NaN is returned. |
| 59 |
.P |
| 60 |
.\" POSIX.1-2008 allows some possible differences for the following two |
| 61 |
.\" domain error cases, but on Linux they are treated the same (AFAICS). |
| 62 |
.\" Nevertheless, we'll mirror POSIX.1 and describe the two cases |
| 63 |
.\" separately. |
| 64 |
If one of |
| 65 |
.I x |
| 66 |
or |
| 67 |
.I y |
| 68 |
is an infinity, the other is 0, and |
| 69 |
.I z |
| 70 |
is not a NaN, |
| 71 |
a domain error occurs, and |
| 72 |
a NaN is returned. |
| 73 |
.\" POSIX.1 says that a NaN or an implementation-defined value shall |
| 74 |
.\" be returned for this case. |
| 75 |
.P |
| 76 |
If one of |
| 77 |
.I x |
| 78 |
or |
| 79 |
.I y |
| 80 |
is an infinity, and the other is 0, and |
| 81 |
.I z |
| 82 |
is a NaN, |
| 83 |
.\" POSIX.1 makes the domain error optional for this case. |
| 84 |
a domain error occurs, and |
| 85 |
a NaN is returned. |
| 86 |
.P |
| 87 |
If |
| 88 |
.I x |
| 89 |
times |
| 90 |
.I y |
| 91 |
is not an infinity times zero (or vice versa), and |
| 92 |
.I z |
| 93 |
is a NaN, |
| 94 |
a NaN is returned. |
| 95 |
.P |
| 96 |
If the result overflows, |
| 97 |
a range error occurs, and |
| 98 |
an infinity with the correct sign is returned. |
| 99 |
.P |
| 100 |
If the result underflows, |
| 101 |
a range error occurs, and |
| 102 |
a signed 0 is returned. |
| 103 |
.SH ERRORS |
| 104 |
See |
| 105 |
.BR math_error (7) |
| 106 |
for information on how to determine whether an error has occurred |
| 107 |
when calling these functions. |
| 108 |
.P |
| 109 |
The following errors can occur: |
| 110 |
.TP |
| 111 |
Domain error: \f[I]x * y + z\f[] \ |
| 112 |
or \f[I]x * y\f[] is invalid. |
| 113 |
.\" .I errno |
| 114 |
.\" is set to |
| 115 |
.\" .BR EDOM . |
| 116 |
An invalid floating-point exception |
| 117 |
.RB ( FE_INVALID ) |
| 118 |
is raised. |
| 119 |
.TP |
| 120 |
Range error: result overflow |
| 121 |
.\" .I errno |
| 122 |
.\" is set to |
| 123 |
.\" .BR ERANGE . |
| 124 |
An overflow floating-point exception |
| 125 |
.RB ( FE_OVERFLOW ) |
| 126 |
is raised. |
| 127 |
.TP |
| 128 |
Range error: result underflow |
| 129 |
.\" .I errno |
| 130 |
.\" is set to |
| 131 |
.\" .BR ERANGE . |
| 132 |
An underflow floating-point exception |
| 133 |
.RB ( FE_UNDERFLOW ) |
| 134 |
is raised. |
| 135 |
.P |
| 136 |
These functions do not set |
| 137 |
.IR errno . |
| 138 |
.\" FIXME . Is it intentional that these functions do not set errno? |
| 139 |
.\" Bug raised: https://www.sourceware.org/bugzilla/show_bug.cgi?id=6801 |
| 140 |
.SH ATTRIBUTES |
| 141 |
For an explanation of the terms used in this section, see |
| 142 |
.BR attributes (7). |
| 143 |
.TS |
| 144 |
allbox; |
| 145 |
lbx lb lb |
| 146 |
l l l. |
| 147 |
Interface Attribute Value |
| 148 |
T{ |
| 149 |
.na |
| 150 |
.nh |
| 151 |
.BR fma (), |
| 152 |
.BR fmaf (), |
| 153 |
.BR fmal () |
| 154 |
T} Thread safety MT-Safe |
| 155 |
.TE |
| 156 |
.SH STANDARDS |
| 157 |
C11, POSIX.1-2008. |
| 158 |
.SH HISTORY |
| 159 |
glibc 2.1. |
| 160 |
C99, POSIX.1-2001. |
| 161 |
.SH SEE ALSO |
| 162 |
.BR remainder (3), |
| 163 |
.BR remquo (3) |