annotate tests/test-fma2.h @ 17415:6550127da196

argp: typo fix * lib/argp-help.c: Typo in comment.
author Alexandre Duret-Lutz <adl@lrde.epita.fr>
date Fri, 17 May 2013 19:01:14 +0200
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of fused multiply-add.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16201
diff changeset
2 Copyright (C) 2011-2013 Free Software Foundation, Inc.
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2011. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Returns 2^e as a DOUBLE. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #define POW2(e) \
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 LDEXP (L_(1.0), e)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* One could define XE_RANGE and YE_RANGE to 5 or 60, but this would slow down
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 the test without the expectation of catching more bugs. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #define XE_RANGE 0
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #define YE_RANGE 0
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* Define to 1 if you want to allow the behaviour of the 'double-double'
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 implementation of 'long double' (seen on IRIX 6.5 and Linux/PowerPC).
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 This floating-point type does not follow IEEE 754. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #if MANT_BIT == LDBL_MANT_BIT && LDBL_MANT_BIT == 2 * DBL_MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 # define FORGIVE_DOUBLEDOUBLE_BUG 1
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 # define FORGIVE_DOUBLEDOUBLE_BUG 0
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 #endif
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* Subnormal numbers appear to not work as expected on IRIX 6.5. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #ifdef __sgi
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 # define MIN_SUBNORMAL_EXP (MIN_EXP - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 #else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 # define MIN_SUBNORMAL_EXP (MIN_EXP - MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 #endif
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 /* Check rounding behaviour. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 static void
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 test_function (DOUBLE (*my_fma) (DOUBLE, DOUBLE, DOUBLE))
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 /* Array mapping n to (-1)^n. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 static const DOUBLE pow_m1[] =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 L_(1.0), - L_(1.0), L_(1.0), - L_(1.0),
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 L_(1.0), - L_(1.0), L_(1.0), - L_(1.0)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 };
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 /* A product x * y that consists of two bits. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 {
16110
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
58 volatile DOUBLE x;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
59 volatile DOUBLE y;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
60 volatile DOUBLE z;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
61 volatile DOUBLE result;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
62 volatile DOUBLE expected;
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 int xs;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 int xe;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 int ys;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 int ye;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 int ze;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 DOUBLE sign;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 for (xs = 0; xs < 2; xs++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 for (xe = -XE_RANGE; xe <= XE_RANGE; xe++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 x = pow_m1[xs] * POW2 (xe); /* (-1)^xs * 2^xe */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 for (ys = 0; ys < 2; ys++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 for (ye = -YE_RANGE; ye <= YE_RANGE; ye++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 y = pow_m1[ys] * POW2 (ye); /* (-1)^ys * 2^ye */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 sign = pow_m1[xs + ys];
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 /* Test addition (same signs). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 for (ze = MIN_EXP - MANT_BIT; ze <= MAX_EXP - 1;)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 z = sign * POW2 (ze); /* (-1)^(xs+ys) * 2^ze */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 if (xe + ye >= ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 expected = sign * POW2 (xe + ye);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 else if (xe + ye > ze - MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 expected = sign * (POW2 (xe + ye) + POW2 (ze));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 ASSERT (result == expected);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 ze++;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 /* Shortcut some values of ze, to speed up the test. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 if (ze == MIN_EXP + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 ze = - 2 * MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 else if (ze == 2 * MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 ze = MAX_EXP - MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 /* Test subtraction (opposite signs). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 for (ze = MIN_EXP - MANT_BIT; ze <= MAX_EXP - 1;)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 z = - sign * POW2 (ze); /* (-1)^(xs+ys+1) * 2^ze */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 if (xe + ye > ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 expected = sign * POW2 (xe + ye);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 else if (xe + ye >= ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 expected = sign * (POW2 (xe + ye) - POW2 (ze));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 else if (xe + ye > ze - 1 - MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 expected = - sign * (POW2 (ze) - POW2 (xe + ye));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 ASSERT (result == expected);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 ze++;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 /* Shortcut some values of ze, to speed up the test. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 if (ze == MIN_EXP + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 ze = - 2 * MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 else if (ze == 2 * MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 ze = MAX_EXP - MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 /* A product x * y that consists of three bits. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 {
16110
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
130 volatile DOUBLE x;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
131 volatile DOUBLE y;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
132 volatile DOUBLE z;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
133 volatile DOUBLE result;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
134 volatile DOUBLE expected;
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 int i;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 int xs;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 int xe;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 int ys;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 int ye;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 int ze;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 DOUBLE sign;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 for (i = 1; i <= MANT_BIT - 1; i++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 for (xs = 0; xs < 2; xs++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 for (xe = -XE_RANGE; xe <= XE_RANGE; xe++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 x = /* (-1)^xs * (2^xe + 2^(xe-i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 pow_m1[xs] * (POW2 (xe) + POW2 (xe - i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 for (ys = 0; ys < 2; ys++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 for (ye = -YE_RANGE; ye <= YE_RANGE; ye++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 y = /* (-1)^ys * (2^ye + 2^(ye-i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 pow_m1[ys] * (POW2 (ye) + POW2 (ye - i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 sign = pow_m1[xs + ys];
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 /* The exact value of x * y is
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 (-1)^(xs+ys) * (2^(xe+ye) + 2^(xe+ye-i+1) + 2^(xe+ye-2*i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 /* Test addition (same signs). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 for (ze = MIN_SUBNORMAL_EXP; ze <= MAX_EXP - 1;)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 z = sign * POW2 (ze); /* (-1)^(xs+ys) * 2^ze */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 if (FORGIVE_DOUBLEDOUBLE_BUG)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 if ((xe + ye > ze
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 && xe + ye < ze + MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 && i == DBL_MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 || (xe + ye == ze + DBL_MANT_BIT && i == DBL_MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 || (xe + ye == ze + MANT_BIT - 1 && i == 1))
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 goto skip1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 if (xe + ye > ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
175 if (2 * i > MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
176 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
177 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
178 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
179 else if (2 * i == MANT_BIT)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
180 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
181 sign * (POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
182 + POW2 (xe + ye - i + 1)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
183 + POW2 (xe + ye - MANT_BIT + 1));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
184 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
185 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
186 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
187 + POW2 (xe + ye - i + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
188 + POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
189 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
190 else if (xe + ye == ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
191 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
192 if (2 * i >= MANT_BIT)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
193 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
194 sign * (POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
195 + POW2 (xe + ye - i + 1)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
196 + POW2 (xe + ye - MANT_BIT + 1));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
197 else if (2 * i == MANT_BIT - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
198 /* round-to-even rounds up */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
199 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
200 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
201 + POW2 (xe + ye - i + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
202 + POW2 (xe + ye - 2 * i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
203 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
204 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
205 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
206 + POW2 (xe + ye - i + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
207 + POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
208 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
209 else if (xe + ye > ze - MANT_BIT + 2 * i)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
210 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
211 sign * (POW2 (ze)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
212 + POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
213 + POW2 (xe + ye - i + 1)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
214 + POW2 (xe + ye - 2 * i));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
215 else if (xe + ye >= ze - MANT_BIT + i)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
216 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
217 sign * (POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
218 + POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
219 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
220 else if (xe + ye == ze - MANT_BIT + i - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
221 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
222 if (i == 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
223 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
224 sign * (POW2 (ze) + POW2 (ze - MANT_BIT + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
225 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
226 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
227 sign * (POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
228 + POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
229 + POW2 (ze - MANT_BIT + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
230 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
231 else if (xe + ye >= ze - MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
232 expected = sign * (POW2 (ze) + POW2 (xe + ye));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
233 else if (xe + ye == ze - MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
234 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
235 sign * (POW2 (ze) + POW2 (ze - MANT_BIT + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
236 else if (xe + ye == ze - MANT_BIT - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
237 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
238 if (i == 1)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
239 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
240 sign * (POW2 (ze) + POW2 (ze - MANT_BIT + 1));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
241 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
242 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
243 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
244 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
245 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
246 ASSERT (result == expected);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
247
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
248 skip1:
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
249 ze++;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
250 /* Shortcut some values of ze, to speed up the test. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
251 if (ze == MIN_EXP + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
252 ze = - 2 * MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
253 else if (ze == 2 * MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
254 ze = MAX_EXP - MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
255 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
256
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
257 /* Test subtraction (opposite signs). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
258 if (i > 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
259 for (ze = MIN_SUBNORMAL_EXP; ze <= MAX_EXP - 1;)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
260 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
261 z = - sign * POW2 (ze); /* (-1)^(xs+ys+1) * 2^ze */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
262 result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
263 if (FORGIVE_DOUBLEDOUBLE_BUG)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
264 if ((xe + ye == ze && i == MANT_BIT - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
265 || (xe + ye > ze
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
266 && xe + ye <= ze + DBL_MANT_BIT - 1
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
267 && i == DBL_MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
268 || (xe + ye >= ze + DBL_MANT_BIT - 1
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
269 && xe + ye < ze + MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
270 && xe + ye == ze + i - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
271 || (xe + ye > ze + DBL_MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
272 && xe + ye < ze + MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
273 && i == DBL_MANT_BIT))
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
274 goto skip2;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
275 if (xe + ye == ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
276 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
277 /* maximal extinction */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
278 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
279 sign * (POW2 (xe + ye - i + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
280 + POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
281 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
282 else if (xe + ye == ze - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
283 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
284 /* significant extinction */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
285 if (2 * i > MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
286 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
287 sign * (- POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
288 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
289 else
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
290 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
291 sign * (- POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
292 + POW2 (xe + ye - i + 1)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
293 + POW2 (xe + ye - 2 * i));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
294 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
295 else if (xe + ye > ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
296 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
297 if (2 * i >= MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
298 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
299 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
300 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
301 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
302 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
303 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
304 + POW2 (xe + ye - i + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
305 + POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
306 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
307 else if (xe + ye == ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
308 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
309 if (2 * i >= MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
310 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
311 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
312 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
313 else if (2 * i == MANT_BIT - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
314 /* round-to-even rounds down */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
315 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
316 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
317 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
318 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
319 /* round-to-even rounds up */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
320 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
321 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
322 + POW2 (xe + ye - i + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
323 + POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
324 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
325 else if (xe + ye >= ze - MANT_BIT + 2 * i)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
326 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
327 sign * (- POW2 (ze)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
328 + POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
329 + POW2 (xe + ye - i + 1)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
330 + POW2 (xe + ye - 2 * i));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
331 else if (xe + ye >= ze - MANT_BIT + i - 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
332 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
333 sign * (- POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
334 + POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
335 + POW2 (xe + ye - i + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
336 else if (xe + ye == ze - MANT_BIT + i - 2)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
337 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
338 sign * (- POW2 (ze)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
339 + POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
340 + POW2 (ze - MANT_BIT));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
341 else if (xe + ye >= ze - MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
342 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
343 sign * (- POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
344 + POW2 (xe + ye));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
345 else if (xe + ye == ze - MANT_BIT - 1)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
346 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
347 sign * (- POW2 (ze)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
348 + POW2 (ze - MANT_BIT));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
349 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
350 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
351 ASSERT (result == expected);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
352
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
353 skip2:
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
354 ze++;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
355 /* Shortcut some values of ze, to speed up the test. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
356 if (ze == MIN_EXP + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
357 ze = - 2 * MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
358 else if (ze == 2 * MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
359 ze = MAX_EXP - MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
360 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
361 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
362 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
363 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
364 /* TODO: Similar tests with
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
365 x = (-1)^xs * (2^xe - 2^(xe-i)), y = (-1)^ys * (2^ye - 2^(ye-i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
366 /* A product x * y that consists of one segment of bits (or, if you prefer,
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
367 two bits, one with positive weight and one with negative weight). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
368 {
16110
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
369 volatile DOUBLE x;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
370 volatile DOUBLE y;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
371 volatile DOUBLE z;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
372 volatile DOUBLE result;
146b5e66e142 fma tests: Avoid shadowing local variables.
Bruno Haible <bruno@clisp.org>
parents: 16044
diff changeset
373 volatile DOUBLE expected;
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
374 int i;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
375 int xs;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
376 int xe;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
377 int ys;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
378 int ye;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
379 int ze;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
380 DOUBLE sign;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
381
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
382 for (i = 1; i <= MANT_BIT - 1; i++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
383 for (xs = 0; xs < 2; xs++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
384 for (xe = -XE_RANGE; xe <= XE_RANGE; xe++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
385 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
386 x = /* (-1)^xs * (2^xe + 2^(xe-i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
387 pow_m1[xs] * (POW2 (xe) + POW2 (xe - i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
388
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
389 for (ys = 0; ys < 2; ys++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
390 for (ye = -YE_RANGE; ye <= YE_RANGE; ye++)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
391 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
392 y = /* (-1)^ys * (2^ye - 2^(ye-i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
393 pow_m1[ys] * (POW2 (ye) - POW2 (ye - i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
394
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
395 sign = pow_m1[xs + ys];
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
396
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
397 /* The exact value of x * y is
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
398 (-1)^(xs+ys) * (2^(xe+ye) - 2^(xe+ye-2*i)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
399
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
400 /* Test addition (same signs). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
401 for (ze = MIN_EXP - MANT_BIT; ze <= MAX_EXP - 1;)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
402 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
403 z = sign * POW2 (ze); /* (-1)^(xs+ys) * 2^ze */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
404 result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
405 if (FORGIVE_DOUBLEDOUBLE_BUG)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
406 if ((xe + ye == ze + MANT_BIT && i > DBL_MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
407 || (xe + ye < ze + MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
408 && xe + ye >= ze
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
409 && i == DBL_MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
410 || (xe + ye < ze
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
411 && xe + ye == ze - MANT_BIT + 2 * i))
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
412 goto skip3;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
413 if (xe + ye > ze + MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
414 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
415 if (2 * i > MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
416 expected = sign * POW2 (xe + ye);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
417 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
418 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
419 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
420 - POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
421 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
422 else if (xe + ye == ze + MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
423 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
424 if (2 * i >= MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
425 expected = sign * POW2 (xe + ye);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
426 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
427 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
428 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
429 - POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
430 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
431 else if (xe + ye >= ze - MANT_BIT + 2 * i)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
432 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
433 if (2 * i > MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
434 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
435 sign * (POW2 (xe + ye) + POW2 (ze));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
436 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
437 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
438 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
439 - POW2 (xe + ye - 2 * i)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
440 + POW2 (ze));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
441 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
442 else if (xe + ye >= ze - MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
443 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
444 sign * (POW2 (ze) + POW2 (xe + ye));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
445 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
446 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
447 ASSERT (result == expected);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
448
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
449 skip3:
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
450 ze++;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
451 /* Shortcut some values of ze, to speed up the test. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
452 if (ze == MIN_EXP + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
453 ze = - 2 * MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
454 else if (ze == 2 * MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
455 ze = MAX_EXP - MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
456 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
457
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
458 /* Test subtraction (opposite signs). */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
459 if (i > 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
460 for (ze = MIN_SUBNORMAL_EXP; ze <= MAX_EXP - 1;)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
461 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
462 z = - sign * POW2 (ze); /* (-1)^(xs+ys+1) * 2^ze */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
463 result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
464 if (FORGIVE_DOUBLEDOUBLE_BUG)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
465 if (xe + ye > ze
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
466 && xe + ye < ze + DBL_MANT_BIT
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
467 && xe + ye == ze + 2 * i - LDBL_MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
468 goto skip4;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
469 if (xe + ye == ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
470 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
471 /* maximal extinction */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
472 expected = sign * - POW2 (xe + ye - 2 * i);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
473 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
474 else if (xe + ye > ze + MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
475 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
476 if (2 * i > MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
477 expected = sign * POW2 (xe + ye);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
478 else if (2 * i == MANT_BIT + 1)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
479 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
480 sign * (POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
481 - POW2 (xe + ye - MANT_BIT));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
482 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
483 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
484 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
485 - POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
486 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
487 else if (xe + ye == ze + MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
488 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
489 if (2 * i > MANT_BIT)
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
490 expected =
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
491 sign * (POW2 (xe + ye)
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
492 - POW2 (xe + ye - MANT_BIT));
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
493 else if (2 * i == MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
494 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
495 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
496 - POW2 (xe + ye - MANT_BIT + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
497 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
498 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
499 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
500 - POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
501 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
502 else if (xe + ye == ze + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
503 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
504 if (2 * i > MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
505 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
506 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
507 - POW2 (xe + ye - MANT_BIT));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
508 else if (2 * i == MANT_BIT + 1)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
509 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
510 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
511 - POW2 (xe + ye - MANT_BIT + 1));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
512 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
513 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
514 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
515 - POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
516 - POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
517 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
518 else if (xe + ye > ze - MANT_BIT + 2 * i)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
519 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
520 if (2 * i > MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
521 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
522 sign * (POW2 (xe + ye) - POW2 (ze));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
523 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
524 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
525 sign * (POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
526 - POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
527 - POW2 (xe + ye - 2 * i));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
528 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
529 else if (xe + ye == ze - MANT_BIT + 2 * i)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
530 expected =
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
531 sign * (- POW2 (ze)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
532 + POW2 (xe + ye)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
533 - POW2 (xe + ye - 2 * i));
16044
566be7372974 fma*: Simplify test.
Bruno Haible <bruno@clisp.org>
parents: 16039
diff changeset
534 else if (xe + ye >= ze - MANT_BIT)
16039
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
535 expected = sign * (- POW2 (ze) + POW2 (xe + ye));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
536 else
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
537 expected = z;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
538 ASSERT (result == expected);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
539
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
540 skip4:
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
541 ze++;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
542 /* Shortcut some values of ze, to speed up the test. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
543 if (ze == MIN_EXP + MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
544 ze = - 2 * MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
545 else if (ze == 2 * MANT_BIT)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
546 ze = MAX_EXP - MANT_BIT - 1;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
547 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
548 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
549 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
550 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
551 /* TODO: Tests with denormalized results. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
552 /* Tests with temporary overflow. */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
553 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
554 volatile DOUBLE x = POW2 (MAX_EXP - 1);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
555 volatile DOUBLE y = POW2 (MAX_EXP - 1);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
556 volatile DOUBLE z = - INFINITY;
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
557 volatile DOUBLE result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
558 ASSERT (result == - INFINITY);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
559 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
560 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
561 volatile DOUBLE x = POW2 (MAX_EXP - 1); /* 2^(MAX_EXP-1) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
562 volatile DOUBLE y = L_(2.0); /* 2^1 */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
563 volatile DOUBLE z = /* -(2^MAX_EXP - 2^(MAX_EXP-MANT_BIT)) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
564 - LDEXP (POW2 (MAX_EXP - 1) - POW2 (MAX_EXP - MANT_BIT - 1), 1);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
565 volatile DOUBLE result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
566 if (!FORGIVE_DOUBLEDOUBLE_BUG)
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
567 ASSERT (result == POW2 (MAX_EXP - MANT_BIT));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
568 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
569 {
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
570 volatile DOUBLE x = POW2 (MAX_EXP - 1); /* 2^(MAX_EXP-1) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
571 volatile DOUBLE y = L_(3.0); /* 3 */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
572 volatile DOUBLE z = - LDEXP (L_(5.0), MAX_EXP - 3); /* -5*2^(MAX_EXP-3) */
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
573 volatile DOUBLE result = my_fma (x, y, z);
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
574 ASSERT (result == LDEXP (L_(7.0), MAX_EXP - 3));
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
575 }
ae7cb951d5b4 Tests for module 'fma'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
576 }