xref: /freebsd/lib/msun/man/fma.3 (revision cbb3ec25236ba72f91cbdf23f8b78b9d1af0cedf)
1.\" Copyright (c) 2005 David Schultz <das@FreeBSD.org>
2.\" All rights reserved.
3.\"
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\"
13.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23.\" SUCH DAMAGE.
24.\"
25.Dd January 22, 2005
26.Dt FMA 3
27.Os
28.Sh NAME
29.Nm fma ,
30.Nm fmaf ,
31.Nm fmal
32.Nd fused multiply-add
33.Sh LIBRARY
34.Lb libm
35.Sh SYNOPSIS
36.In math.h
37.Ft double
38.Fn fma "double x" "double y" "double z"
39.Ft float
40.Fn fmaf "float x" "float y" "float z"
41.Ft long double
42.Fn fmal "long double x" "long double y" "long double z"
43.Sh DESCRIPTION
44The
45.Fn fma ,
46.Fn fmaf ,
47and
48.Fn fmal
49functions return
50.No "(x * y) + z" ,
51computed with only one rounding error.
52Using the ordinary multiplication and addition operators, by contrast,
53results in two roundings: one for the intermediate product and one for
54the final result.
55.Pp
56For instance, the expression
57.No "1.2e100 * 2.0e208 - 1.4e308"
58produces \*(If due to overflow in the intermediate product, whereas
59.No "fma(1.2e100, 2.0e208, -1.4e308)"
60returns approximately 1.0e308.
61.Pp
62The fused multiply-add operation is often used to improve the
63accuracy of calculations such as dot products.
64It may also be used to improve performance on machines that implement
65it natively.
66The macros
67.Dv FP_FAST_FMA ,
68.Dv FP_FAST_FMAF
69and
70.Dv FP_FAST_FMAL
71may be defined in
72.In math.h
73to indicate that
74.Fn fma ,
75.Fn fmaf ,
76and
77.Fn fmal
78(respectively) have comparable or faster speed than a multiply
79operation followed by an add operation.
80.Sh IMPLEMENTATION NOTES
81In general, these routines will behave as one would expect if
82.No "x * y + z"
83were computed with unbounded precision and range,
84then rounded to the precision of the return type.
85However, on some platforms, if
86.Fa z
87is \*(Na, these functions may not raise an exception even
88when the computation of
89.No "x * y"
90would have otherwise generated an invalid exception.
91.Sh SEE ALSO
92.Xr fenv 3 ,
93.Xr math 3
94.Sh STANDARDS
95The
96.Fn fma ,
97.Fn fmaf ,
98and
99.Fn fmal
100functions conform to
101.St -isoC-99 .
102A fused multiply-add operation with virtually identical
103characteristics appears in IEEE draft standard 754R.
104.Sh HISTORY
105The
106.Fn fma
107and
108.Fn fmaf
109routines first appeared in
110.Fx 5.4 ,
111and
112.Fn fmal
113appeared in
114.Fx 6.0 .
115