usleep tests: Avoid failure due to known Cygwin 3.5.3 bug.
[gnulib.git] / tests / test-expm1.h
blobfc92617a05e07f9a9e3f3b8588f49598687c6d0e
1 /* Test of expm1*() function family.
2 Copyright (C) 2012-2024 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/>. */
17 static void
18 test_function (void)
20 int i;
21 int j;
22 const DOUBLE TWO_MANT_DIG =
23 /* Assume MANT_DIG <= 5 * 31.
24 Use the identity
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 /* Arguments near zero. */
34 DOUBLE x;
36 for (i = -1, x = L_(0.5); i >= MIN_EXP; i--, x *= L_(0.5))
38 volatile DOUBLE y;
40 y = EXPM1 (x);
41 ASSERT (y >= x);
42 ASSERT (y < L_(1.5) * x);
44 y = EXPM1 (- x);
45 ASSERT (y >= - x);
46 ASSERT (y < - L_(0.5) * x);
50 /* Randomized tests. */
52 /* Error bound, in ulps. */
53 const DOUBLE err_bound =
54 (sizeof (DOUBLE) > sizeof (double) ?
55 #if defined __i386__ && defined __NetBSD__
56 L_(1025.0)
57 #elif defined __i386__ && defined __FreeBSD__
58 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
59 precision in the compiler but 64 bits of precision at runtime. See
60 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>.
61 The compiler has truncated all 'long double' literals in expl.c to
62 53 bits of precision. */
63 L_(1024.0)
64 #else
65 L_(5.0)
66 #endif
67 : L_(5.0));
69 for (i = 0; i < SIZEOF (RANDOM); i++)
71 DOUBLE x = L_(2.0) * RANDOM[i]; /* 0.0 <= x <= 2.0 */
72 DOUBLE y = EXPM1 (x);
73 DOUBLE z = EXPM1 (- x);
74 DOUBLE err = y + (1 + y) * z;
75 ASSERT (y >= L_(0.0));
76 ASSERT (z <= L_(0.0));
77 ASSERT (err > - err_bound / TWO_MANT_DIG
78 && err < err_bound / TWO_MANT_DIG);
83 /* Error bound, in ulps. */
84 const DOUBLE err_bound =
85 (sizeof (DOUBLE) > sizeof (double) ?
86 #if defined __i386__ && defined __FreeBSD__
87 L_(1536.0)
88 #elif defined __i386__ && defined __NetBSD__
89 L_(1026.0)
90 #else
91 L_(11.0)
92 #endif
93 : L_(9.0));
95 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
96 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
98 DOUBLE x = L_(2.0) * RANDOM[i] - L_(1.0); /* -1.0 <= x <= 1.0 */
99 DOUBLE y = L_(2.0) * RANDOM[j] - L_(1.0); /* -1.0 <= y <= 1.0 */
100 DOUBLE z = - x - y;
101 /* Approximately x + y + z = 0. */
103 DOUBLE a = EXPM1 (x);
104 DOUBLE b = EXPM1 (y);
105 DOUBLE c = EXPM1 (z);
106 DOUBLE err = a + (1 + a) * (b + (1 + b) * c);
107 ASSERT (err > - err_bound / TWO_MANT_DIG
108 && err < err_bound / TWO_MANT_DIG);
114 volatile DOUBLE x;
115 DOUBLE y;