annotate tests/test-log10.h @ 40231:9b3c79fdfe0b

strtod: fix clash with strtold Problem reported for RHEL 5 by Jesse Caldwell (Bug#34817). * lib/strtod.c (compute_minus_zero, minus_zero): Simplify by remving the macro / external variable, and having just a function. User changed. This avoids the need for an external variable that might clash.
author Paul Eggert <eggert@cs.ucla.edu>
date Mon, 11 Mar 2019 16:40:29 -0700
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16733
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of log10*() function family.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2012-2019 Free Software Foundation, Inc.
16733
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
d9812d72970c log10 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
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
16733
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 static void
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 test_function (void)
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 int i;
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 int j;
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 const DOUBLE TWO_MANT_DIG =
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Assume MANT_DIG <= 5 * 31.
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 Use the identity
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* Pole. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 DOUBLE z = LOG10 (L_(0.0));
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 ASSERT (z == - HUGEVAL);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 DOUBLE z = LOG10 (MINUS_ZERO);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 ASSERT (z == - HUGEVAL);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* Randomized tests. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 /* Error bound, in ulps. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 const DOUBLE err_bound =
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 (sizeof (DOUBLE) > sizeof (double) ?
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #if defined __i386__ && defined __FreeBSD__
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 precision in the compiler but 64 bits of precision at runtime. See
19439
8bfc20b57265 maint: shorten https://lists.gnu.org/archive/html/... links
Jim Meyering <meyering@fb.com>
parents: 19192
diff changeset
50 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>.
16733
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 The compiler has truncated all 'long double' literals in log10l.c to
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 53 bits of precision. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 L_(18.0)
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 #else
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 L_(3.0)
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 #endif
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 : L_(3.0));
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 for (i = 0; i < SIZEOF (RANDOM); i++)
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 DOUBLE x = L_(16.0) * RANDOM[i] + L_(1.0); /* 1.0 <= x <= 17.0 */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 DOUBLE y = LOG10 (x);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 DOUBLE z = LOG10 (L_(1.0) / x);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 DOUBLE err = y + z;
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 ASSERT (y >= L_(0.0));
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 ASSERT (z <= L_(0.0));
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 ASSERT (err > - err_bound / TWO_MANT_DIG
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 && err < err_bound / TWO_MANT_DIG);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* Error bound, in ulps. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 const DOUBLE err_bound =
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 (sizeof (DOUBLE) > sizeof (double) ?
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 #if defined __i386__ && defined __FreeBSD__
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 precision in the compiler but 64 bits of precision at runtime. See
19439
8bfc20b57265 maint: shorten https://lists.gnu.org/archive/html/... links
Jim Meyering <meyering@fb.com>
parents: 19192
diff changeset
79 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>.
16733
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 The compiler has truncated all 'long double' literals in log10l.c to
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 53 bits of precision. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 L_(38.0)
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 #else
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 L_(5.0)
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 #endif
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 : L_(5.0));
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87
16750
8b54ed378c86 log10* tests: Speed up.
Bruno Haible <bruno@clisp.org>
parents: 16733
diff changeset
88 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
8b54ed378c86 log10* tests: Speed up.
Bruno Haible <bruno@clisp.org>
parents: 16733
diff changeset
89 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
16733
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 {
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 DOUBLE x = L_(17.0) / (L_(16.0) - L_(15.0) * RANDOM[i]) - L_(1.0);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 DOUBLE y = L_(17.0) / (L_(16.0) - L_(15.0) * RANDOM[j]) - L_(1.0);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 /* 1/16 <= x,y <= 16 */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 DOUBLE z = L_(1.0) / (x * y);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 /* Approximately x * y * z = 1. */
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 DOUBLE err = LOG10 (x) + LOG10 (y) + LOG10 (z);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 ASSERT (err > - err_bound / TWO_MANT_DIG
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 && err < err_bound / TWO_MANT_DIG);
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 volatile DOUBLE x;
d9812d72970c log10 tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 DOUBLE y;