annotate tests/test-cbrt.h @ 16817:7747cb9b54b9

unistd_h: make it easier to avoid sys_types_h This is useful for Emacs, which has its own method of porting to Windows, and which therefore does not need the sys_types_h module. * m4/off_t.m4: New file, defining gl_TYPE_OFF_T, which contains code moved here from gl_SYS_TYPES_H. * m4/sys_types_h.m4 (gl_SYS_TYPES_H): Require it instead of using the code directly. * m4/unistd_h.m4 (gl_UNISTD_H): Require gl_TYPE_OFF_T, not gl_SYS_TYPES_H. * modules/sys_types (Files): * modules/unistd (Files): Add m4/off_t.m4.
author Paul Eggert <eggert@cs.ucla.edu>
date Fri, 04 May 2012 13:05:31 -0700
parents 2faf2762788a
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16575
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of cbrt*() function family.
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2012 Free Software Foundation, Inc.
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
2faf2762788a cbrt* 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
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 static void
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 test_function (void)
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 {
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 int i;
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 int j;
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 const DOUBLE TWO_MANT_DIG =
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Assume MANT_DIG <= 5 * 31.
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 Use the identity
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 /* Randomized tests. */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 for (i = 0; i < SIZEOF (RANDOM); i++)
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 {
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 DOUBLE y = CBRT (x);
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 DOUBLE err = y * y * y - x;
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 ASSERT (err > - L_(4.0) * L_(16.0) / TWO_MANT_DIG
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 && err < L_(4.0) * L_(16.0) / TWO_MANT_DIG);
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 }
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 for (i = 0; i < SIZEOF (RANDOM) / 5; i++)
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 for (j = 0; j < SIZEOF (RANDOM) / 5; j++)
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 {
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 DOUBLE x = L_(32.0) * RANDOM[i] - L_(16.0); /* -16.0 <= x <= 16.0 */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 DOUBLE y = L_(32.0) * RANDOM[j] - L_(16.0); /* -16.0 <= y <= 16.0 */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 if (x != L_(0.0) && y != L_(0.0))
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 DOUBLE z = L_(1.0) / (x * y);
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 /* Approximately x * y * z = 1. */
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 DOUBLE p = CBRT (x) * CBRT (y) * CBRT (z);
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 ASSERT (p > L_(1.0) - L_(8.0) / TWO_MANT_DIG
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 && p < L_(1.0) + L_(8.0) / TWO_MANT_DIG);
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 }
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 }
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 }
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 volatile DOUBLE x;
2faf2762788a cbrt* tests: More tests.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 DOUBLE y;