1 /* Test of exp*() function family.
2 Copyright (C) 2012-2020 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 <https://www.gnu.org/licenses/>. */
22 const DOUBLE TWO_MANT_DIG
=
23 /* Assume MANT_DIG <= 5 * 31.
25 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
26 (DOUBLE
) (1U << ((MANT_DIG
- 1) / 5))
27 * (DOUBLE
) (1U << ((MANT_DIG
- 1 + 1) / 5))
28 * (DOUBLE
) (1U << ((MANT_DIG
- 1 + 2) / 5))
29 * (DOUBLE
) (1U << ((MANT_DIG
- 1 + 3) / 5))
30 * (DOUBLE
) (1U << ((MANT_DIG
- 1 + 4) / 5));
32 /* Randomized tests. */
34 /* Error bound, in ulps. */
35 const DOUBLE err_bound
=
36 (sizeof (DOUBLE
) > sizeof (double) ?
37 #if defined __i386__ && defined __FreeBSD__
38 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
39 precision in the compiler but 64 bits of precision at runtime. See
40 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>.
41 The compiler has truncated all 'long double' literals in expl.c to
42 53 bits of precision. */
49 for (i
= 0; i
< SIZEOF (RANDOM
); i
++)
51 DOUBLE x
= L_(16.0) * RANDOM
[i
]; /* 0.0 <= x <= 16.0 */
54 DOUBLE err
= y
* z
- L_(1.0);
57 ASSERT (err
> - err_bound
/ TWO_MANT_DIG
58 && err
< err_bound
/ TWO_MANT_DIG
);
63 /* Error bound, in ulps. */
64 const DOUBLE err_bound
=
65 (sizeof (DOUBLE
) > sizeof (double) ?
66 #if defined __i386__ && defined __FreeBSD__
73 for (i
= 0; i
< SIZEOF (RANDOM
) / 5; i
++)
74 for (j
= 0; j
< SIZEOF (RANDOM
) / 5; j
++)
76 DOUBLE x
= L_(32.0) * RANDOM
[i
] - L_(16.0); /* -16.0 <= x <= 16.0 */
77 DOUBLE y
= L_(32.0) * RANDOM
[j
] - L_(16.0); /* -16.0 <= y <= 16.0 */
79 /* Approximately x + y + z = 0. */
80 DOUBLE err
= EXP (x
) * EXP (y
) * EXP (z
) - L_(1.0);
81 ASSERT (err
> - err_bound
/ TWO_MANT_DIG
82 && err
< err_bound
/ TWO_MANT_DIG
);