annotate tests/test-ceilf2.c @ 12043:fc84db4ef49d

test-unlinkat: enhance test, to expose Solaris 9 bug Share the unlink tests with unlinkat. * tests/test-unlink.c (main): Factor guts... * tests/test-unlink.h (test_rmdir_func): ...into new file. * tests/test-rmdir.h (test_rmdir_func): Add parameter. * tests/test-rmdir.c (main): Adjust caller. * tests/test-unlinkat.c (main): Likewise. Add unlink tests. (unlinker): New helper function. (rmdirat): Enhance check. * modules/rmdir-tests (Depends-on): Add stdbool. * modules/unlink-tests (Depends-on): Likewise. (Files): Add test-unlink.h. * modules/openat-tests (Files): Likewise. (Depends-on): Add unlinkdir. Signed-off-by: Eric Blake <ebb9@byu.net>
author Eric Blake <ebb9@byu.net>
date Thu, 17 Sep 2009 22:16:56 -0600
parents ebb7ea0c94e8
children e8d2c6fc33ad
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of rounding towards positive infinity.
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9370
diff changeset
2 Copyright (C) 2007-2008 Free Software Foundation, Inc.
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 #include <config.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #include <math.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <float.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <stdbool.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #include <stdint.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <stdio.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 #include <stdlib.h>
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28
10264
ebb7ea0c94e8 Rename isnand.h to isnand-nolibm.h, similarly for isnanf.h.
Ben Pfaff <blp@cs.stanford.edu>
parents: 9889
diff changeset
29 #include "isnanf-nolibm.h"
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 #define ASSERT(expr) \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 do \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 { \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 if (!(expr)) \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 { \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 fprintf (stderr, "%s:%d: assertion failed\n", __FILE__, __LINE__); \
9889
0be6f1ab456d Flush the standard error stream before aborting.
Bruno Haible <bruno@clisp.org>
parents: 9370
diff changeset
37 fflush (stderr); \
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 abort (); \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 } \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 } \
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 while (0)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 /* The reference implementation, taken from lib/ceil.c. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 #define DOUBLE float
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #define MANT_DIG FLT_MANT_DIG
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 #define L_(literal) literal##f
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 /* 2^(MANT_DIG-1). */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 static const DOUBLE TWO_MANT_DIG =
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 /* Assume MANT_DIG <= 5 * 31.
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 Use the identity
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 DOUBLE
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ceilf_reference (DOUBLE x)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 /* The use of 'volatile' guarantees that excess precision bits are dropped
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 at each addition step and before the following comparison at the caller's
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 site. It is necessary on x86 systems where double-floats are not IEEE
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 compliant by default, to avoid that the results become platform and compiler
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 option dependent. 'volatile' is a portable alternative to gcc's
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 -ffloat-store option. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 volatile DOUBLE y = x;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 volatile DOUBLE z = y;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 if (z > L_(0.0))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 /* Avoid rounding errors for values near 2^k, where k >= MANT_DIG-1. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 if (z < TWO_MANT_DIG)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 /* Round to the next integer (nearest or up or down, doesn't matter). */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 z += TWO_MANT_DIG;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 z -= TWO_MANT_DIG;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 /* Enforce rounding up. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 if (z < y)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 z += L_(1.0);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 else if (z < L_(0.0))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 if (z > - TWO_MANT_DIG)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 /* Round to the next integer (nearest or up or down, doesn't matter). */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 z -= TWO_MANT_DIG;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 z += TWO_MANT_DIG;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 /* Enforce rounding up. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 if (z < y)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 z += L_(1.0);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 return z;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
101
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 /* Test for equality. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 static int
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 equal (DOUBLE x, DOUBLE y)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 return (isnanf (x) ? isnanf (y) : x == y);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 /* Test whether the result for a given argument is correct. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 static bool
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 correct_result_p (DOUBLE x, DOUBLE result)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 return
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 (x > 0 && x <= 1 ? result == L_(1.0) :
9370
4e720cd88140 Don't rely on excess precision: -4 > -3.00000024 - 1 can evaluate to false
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
116 x + 1 > x ? result >= x && result <= x + 1 && result - x < 1 :
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 equal (result, x));
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 /* Test the function for a given argument. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 static int
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 check (float x)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 /* If the reference implementation is incorrect, bail out immediately. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 float reference = ceilf_reference (x);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126 ASSERT (correct_result_p (x, reference));
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 /* If the actual implementation is wrong, return an error code. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 float result = ceilf (x);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 if (correct_result_p (x, result))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131 return 0;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 else
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 fprintf (stderr, "ceilf %g(%a) = %g(%a) or %g(%a)?\n",
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135 x, x, reference, reference, result, result);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 return 1;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
137 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
138 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
139 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
140
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
141 #define NUM_HIGHBITS 12
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
142 #define NUM_LOWBITS 4
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
143
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
144 int
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
145 main ()
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
146 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
147 unsigned int highbits;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
148 unsigned int lowbits;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
149 int error = 0;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
150 for (highbits = 0; highbits < (1 << NUM_HIGHBITS); highbits++)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
151 for (lowbits = 0; lowbits < (1 << NUM_LOWBITS); lowbits++)
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
152 {
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
153 /* Combine highbits and lowbits into a floating-point number,
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
154 sign-extending the lowbits to 32-NUM_HIGHBITS bits. */
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
155 union { float f; uint32_t i; } janus;
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
156 janus.i = ((uint32_t) highbits << (32 - NUM_HIGHBITS))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
157 | ((uint32_t) ((int32_t) ((uint32_t) lowbits << (32 - NUM_LOWBITS))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
158 >> (32 - NUM_LOWBITS - NUM_HIGHBITS))
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
159 >> NUM_HIGHBITS);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
160 error |= check (janus.f);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
161 }
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
162 return (error ? 1 : 0);
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
163 }