1 /* Test of fused multiply-add.
2 Copyright (C) 2011 Free Software Foundation, Inc.
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
20 test_function (DOUBLE (*my_fma) (DOUBLE, DOUBLE, DOUBLE))
25 volatile DOUBLE result;
26 volatile DOUBLE expected;
28 /* Combinations with NaN. */
29 /* "If x or y are NaN, a NaN shall be returned." */
34 result = my_fma (x, y, z);
35 ASSERT (ISNAN (result));
41 result = my_fma (x, y, z);
42 ASSERT (ISNAN (result));
48 result = my_fma (x, y, z);
49 ASSERT (ISNAN (result));
55 result = my_fma (x, y, z);
56 ASSERT (ISNAN (result));
62 result = my_fma (x, y, z);
63 ASSERT (ISNAN (result));
69 result = my_fma (x, y, z);
70 ASSERT (ISNAN (result));
72 /* "If x*y is not 0*Inf nor Inf*0 and z is a NaN, a NaN shall be returned." */
77 result = my_fma (x, y, z);
78 ASSERT (ISNAN (result));
80 /* "If one of x and y is infinite, the other is zero, and z is a NaN, a NaN
81 shall be returned and a domain error may occur." */
86 result = my_fma (x, y, z);
87 ASSERT (ISNAN (result));
93 result = my_fma (x, y, z);
94 ASSERT (ISNAN (result));
97 /* Combinations with Infinity. */
98 /* "If x multiplied by y is an exact infinity and z is also an infinity but
99 with the opposite sign, a domain error shall occur, and either a NaN
100 (if supported), or an implementation-defined value shall be returned." */
105 result = my_fma (x, y, z);
106 ASSERT (ISNAN (result));
112 result = my_fma (x, y, z);
113 ASSERT (ISNAN (result));
119 result = my_fma (x, y, z);
120 ASSERT (ISNAN (result));
126 result = my_fma (x, y, z);
127 ASSERT (ISNAN (result));
129 /* "If one of x and y is infinite, the other is zero, and z is not a NaN, a
130 domain error shall occur, and either a NaN (if supported), or an
131 implementation-defined value shall be returned." */
136 result = my_fma (x, y, z);
137 ASSERT (ISNAN (result));
143 result = my_fma (x, y, z);
144 ASSERT (ISNAN (result));
146 /* Infinite results. */
151 result = my_fma (x, y, z);
153 ASSERT (result == expected);
159 result = my_fma (x, y, z);
161 ASSERT (result == expected);
167 result = my_fma (x, y, z);
168 expected = - INFINITY;
169 ASSERT (result == expected);
175 result = my_fma (x, y, z);
177 ASSERT (result == expected);
183 result = my_fma (x, y, z);
184 expected = - INFINITY;
185 ASSERT (result == expected);
188 /* Combinations with zero. */
193 result = my_fma (x, y, z);
195 ASSERT (result == expected);
201 result = my_fma (x, y, z);
203 ASSERT (result == expected);
209 result = my_fma (x, y, z);
211 ASSERT (result == expected);