annotate tests/test-exp.h @ 17593:d1e383af69e2

manywarnings: remove -Wmudflap * m4/manywarnings.m4 (gl_MANYWARN_ALL_GCC): Remove -Wmudflap, since it is no longer supported in gcc-4.9-to-be.
author Jim Meyering <meyering@fb.com>
date Thu, 02 Jan 2014 16:55:04 -0800
parents 344018b6e5d7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16577
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of exp*() function family.
17587
344018b6e5d7 maint: update copyright
Eric Blake <eblake@redhat.com>
parents: 17249
diff changeset
2 Copyright (C) 2012-2014 Free Software Foundation, Inc.
16577
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 static void
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 test_function (void)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 {
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 int i;
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 int j;
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 const DOUBLE TWO_MANT_DIG =
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Assume MANT_DIG <= 5 * 31.
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 Use the identity
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* Randomized tests. */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 /* Error bound, in ulps. */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 const DOUBLE err_bound =
16653
4d95f1c07c62 math tests: Small simplification.
Bruno Haible <bruno@clisp.org>
parents: 16577
diff changeset
36 (sizeof (DOUBLE) > sizeof (double) ?
16577
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 #if defined __i386__ && defined __FreeBSD__
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 precision in the compiler but 64 bits of precision at runtime. See
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 <http://lists.gnu.org/archive/html/bug-gnulib/2008-07/msg00063.html>.
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 The compiler has truncated all 'long double' literals in expl.c to
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 53 bits of precision. */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 L_(1350.0)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 #else
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 L_(4.0)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #endif
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 : L_(2.0));
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 for (i = 0; i < SIZEOF (RANDOM); i++)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 DOUBLE y = EXP (x);
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 DOUBLE z = EXP (- x);
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 DOUBLE err = y * z - L_(1.0);
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 ASSERT (y > L_(0.0));
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 ASSERT (z > L_(0.0));
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 ASSERT (err > - err_bound / TWO_MANT_DIG
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 && err < err_bound / TWO_MANT_DIG);
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 }
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 }
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 {
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* Error bound, in ulps. */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 const DOUBLE err_bound =
16653
4d95f1c07c62 math tests: Small simplification.
Bruno Haible <bruno@clisp.org>
parents: 16577
diff changeset
65 (sizeof (DOUBLE) > sizeof (double) ?
16577
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 #if defined __i386__ && defined __FreeBSD__
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 L_(2400.0)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 #else
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 L_(24.0)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 #endif
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 : L_(24.0));
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 {
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 DOUBLE y = L_(32.0) * RANDOM[j] - L_(16.0); /* -16.0 <= y <= 16.0 */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 DOUBLE z = - x - y;
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 /* Approximately x + y + z = 0. */
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 DOUBLE err = EXP (x) * EXP (y) * EXP (z) - L_(1.0);
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 ASSERT (err > - err_bound / TWO_MANT_DIG
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 && err < err_bound / TWO_MANT_DIG);
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 }
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 }
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 }
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 volatile DOUBLE x;
7bea32ad5560 exp* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 DOUBLE y;