annotate tests/test-log1p.h @ 40057:b06060465f09

maint: Run 'make update-copyright'
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 01 Jan 2019 00:25:11 +0100
parents 10eb9086bea0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16656
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of log1p*() 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.
16656
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
a7869cc6ce1f log1p 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
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
a7869cc6ce1f log1p 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/>. */
16656
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 static void
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 test_function (void)
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 {
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 int i;
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 int j;
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 const DOUBLE TWO_MANT_DIG =
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Assume MANT_DIG <= 5 * 31.
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 Use the identity
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* Pole. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 {
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 DOUBLE z = LOG1P (L_(-1.0));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 ASSERT (z == - HUGEVAL);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 }
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 /* Randomized tests. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 {
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Error bound, in ulps. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 const DOUBLE err_bound =
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 (sizeof (DOUBLE) > sizeof (double) ?
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #if defined __i386__ && defined __FreeBSD__
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 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
46 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>.
16656
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 The compiler has truncated all 'long double' literals in log1pl.c to
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 53 bits of precision. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 L_(900.0)
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 #else
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 L_(26.0)
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 #endif
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 : L_(13.0));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 for (i = 0; i < SIZEOF (RANDOM); i++)
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 {
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 DOUBLE x = L_(16.0) * RANDOM[i]; /* 0.0 <= x <= 16.0 */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 DOUBLE y = LOG1P (x);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 DOUBLE z = LOG1P (- x / (L_(1.0) + x));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 DOUBLE err = y + z;
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 ASSERT (y >= L_(0.0));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ASSERT (z <= L_(0.0));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 ASSERT (err > - err_bound / TWO_MANT_DIG
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 && err < err_bound / TWO_MANT_DIG);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 }
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 }
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 {
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 /* Error bound, in ulps. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 const DOUBLE err_bound =
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 (sizeof (DOUBLE) > sizeof (double) ?
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 #if defined __i386__ && defined __FreeBSD__
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* On FreeBSD/x86 6.4, the 'long double' type really has only 53 bits of
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 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
75 <https://lists.gnu.org/r/bug-gnulib/2008-07/msg00063.html>.
16656
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 The compiler has truncated all 'long double' literals in log1pl.c to
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 53 bits of precision. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 L_(1020.0)
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 #else
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 L_(65.0)
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 #endif
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 : L_(61.0));
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83
16672
b35866abe7d5 log1p* tests: Reduce running time of tests.
Bruno Haible <bruno@clisp.org>
parents: 16656
diff changeset
84 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
b35866abe7d5 log1p* tests: Reduce running time of tests.
Bruno Haible <bruno@clisp.org>
parents: 16656
diff changeset
85 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
16656
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 {
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 DOUBLE x = L_(17.0) / (L_(16.0) - L_(15.0) * RANDOM[i]) - L_(2.0);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 DOUBLE y = L_(17.0) / (L_(16.0) - L_(15.0) * RANDOM[j]) - L_(2.0);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 /* -15/16 <= x,y <= 15 */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 DOUBLE z = L_(1.0) / ((L_(1.0) + x) * (L_(1.0) + y)) - L_(1.0);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 /* Approximately (1+x) * (1+y) * (1+z) = 1. */
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 DOUBLE err = LOG1P (x) + LOG1P (y) + LOG1P (z);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 ASSERT (err > - err_bound / TWO_MANT_DIG
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 && err < err_bound / TWO_MANT_DIG);
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 }
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 }
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 }
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 volatile DOUBLE x;
a7869cc6ce1f log1p tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 DOUBLE y;