annotate tests/test-floor2.c @ 40196:e63f5d3edab5

relocatable-prog: Update documentation. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Feb 2019 01:49:15 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of rounding towards negative infinity.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2007-2019 Free Software Foundation, Inc.
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
e0c1a15af0da Tests for module 'floor'.
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/>. */
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* When this test fails on some platform, build it together with the gnulib
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 module 'fprintf-posix' for optimal debugging output. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #include <config.h>
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <math.h>
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <float.h>
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdbool.h>
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 #include <stdint.h>
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #include <stdio.h>
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #include "isnand-nolibm.h"
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 #include "macros.h"
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
16506
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
34 /* MSVC with option -fp:strict refuses to compile constant initializers that
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
35 contain floating-point operations. Pacify this compiler. */
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
36 #ifdef _MSC_VER
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
37 # pragma fenv_access (off)
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
38 #endif
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
39
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 /* The reference implementation, taken from lib/floor.c. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 #define DOUBLE double
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 #define MANT_DIG DBL_MANT_DIG
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 #define L_(literal) literal
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 /* 2^(MANT_DIG-1). */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 static const DOUBLE TWO_MANT_DIG =
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 /* Assume MANT_DIG <= 5 * 31.
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 Use the identity
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 DOUBLE
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 floor_reference (DOUBLE x)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 /* The use of 'volatile' guarantees that excess precision bits are dropped
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 at each addition step and before the following comparison at the caller's
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 site. It is necessary on x86 systems where double-floats are not IEEE
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 compliant by default, to avoid that the results become platform and compiler
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 option dependent. 'volatile' is a portable alternative to gcc's
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 -ffloat-store option. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 volatile DOUBLE y = x;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 volatile DOUBLE z = y;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 if (z > L_(0.0))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 {
13991
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13974
diff changeset
72 /* For 0 < x < 1, return +0.0 even if the current rounding mode is
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13974
diff changeset
73 FE_DOWNWARD. */
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13974
diff changeset
74 if (z < L_(1.0))
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13974
diff changeset
75 z = L_(0.0);
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */
13991
525bc52bc59f floor: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 13974
diff changeset
77 else if (z < TWO_MANT_DIG)
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 /* Round to the next integer (nearest or up or down, doesn't matter). */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 z += TWO_MANT_DIG;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 z -= TWO_MANT_DIG;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 /* Enforce rounding down. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 if (z > y)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 z -= L_(1.0);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 else if (z < L_(0.0))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 /* Work around ICC's desire to optimize denormal floats to 0. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 if (z > -DBL_MIN)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 return L_(-1.0);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 if (z > - TWO_MANT_DIG)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 /* Round to the next integer (nearest or up or down, doesn't matter). */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 z -= TWO_MANT_DIG;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 z += TWO_MANT_DIG;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 /* Enforce rounding down. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 if (z > y)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 z -= L_(1.0);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 return z;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 /* Test for equality. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 static int
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 equal (DOUBLE x, DOUBLE y)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 return (isnand (x) ? isnand (y) : x == y);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 /* Test whether the result for a given argument is correct. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 static bool
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 correct_result_p (DOUBLE x, DOUBLE result)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 return
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 (x < 0 && x >= -1 ? result == - L_(1.0) :
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 x - 1 < x ? result <= x && result >= x - 1 && x - result < 1 :
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 equal (result, x));
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 /* Test the function for a given argument. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 static int
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 check (double x)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 /* If the reference implementation is incorrect, bail out immediately. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 double reference = floor_reference (x);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 ASSERT (correct_result_p (x, reference));
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 /* If the actual implementation is wrong, return an error code. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 double result = floor (x);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 if (correct_result_p (x, result))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 return 0;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 else
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 #if GNULIB_TEST_FPRINTF_POSIX
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 fprintf (stderr, "floor %g(%a) = %g(%a) or %g(%a)?\n",
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140 x, x, reference, reference, result, result);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 #endif
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 return 1;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 #define NUM_HIGHBITS 15
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 #define NUM_LOWBITS 4
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 int
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 main ()
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 {
14015
41026f5e29c1 stdint: avoid HP-UX 10.20 preprocessor bug
Eric Blake <eblake@redhat.com>
parents: 13991
diff changeset
153 #ifdef UINT64_MAX
13974
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 unsigned int highbits;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 unsigned int lowbits;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 int error = 0;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++)
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 {
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 /* Combine highbits and lowbits into a floating-point number,
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 sign-extending the lowbits to 64-NUM_HIGHBITS bits. */
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 union { double f; uint64_t i; } janus;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 janus.i = ((uint64_t) highbits << (64 - NUM_HIGHBITS))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
164 | ((uint64_t) ((int64_t) ((uint64_t) lowbits << (64 - NUM_LOWBITS))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
165 >> (64 - NUM_LOWBITS - NUM_HIGHBITS))
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
166 >> NUM_HIGHBITS);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
167 error |= check (janus.f);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
168 }
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
169 return (error ? 1 : 0);
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
170 #else
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
171 fprintf (stderr, "Skipping test: no 64-bit integer type available\n");
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
172 return 77;
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
173 #endif
e0c1a15af0da Tests for module 'floor'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
174 }