annotate lib/ceil.c @ 17463:203c036eb0c6

bootstrap: support checksum utils without a --status option * build-aux/bootstrap: Only look for sha1sum if updating po files. Add sha1 to the list of supported checksum utils since it's now supported through adjustments below. (update_po_files): Remove the use of --status in a way that will suppress all error messages, but since this is only used to minimize updates, it shouldn't cause an issue. Exit early if there is a problem updating the po file checksums. (find_tool): Remove the check for --version support as this is optional as per commit 86186b17. Don't even check for the presence of the command as if that is needed, it's supported through configuring prerequisites in bootstrap.conf. Prompt that when a tool isn't found, one can define an environment variable to add to the hardcoded search list.
author Pádraig Brady <P@draigBrady.com>
date Thu, 08 Aug 2013 11:08:49 +0100 (2013-08-08)
parents e542fd46ad6f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Round towards positive infinity.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16506
diff changeset
2 Copyright (C) 2007, 2010-2013 Free Software Foundation, Inc.
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9295
diff changeset
4 This program is free software: you can redistribute it and/or modify
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9295
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9295
diff changeset
7 (at your option) any later version.
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
9309
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9295
diff changeset
14 You should have received a copy of the GNU General Public License
bbbbbf4cd1c5 Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents: 9295
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Bruno Haible <bruno@clisp.org>, 2007. */
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
15925
e9d2edcbd10e ceill: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
19 #if ! defined USE_LONG_DOUBLE
e9d2edcbd10e ceill: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
20 # include <config.h>
e9d2edcbd10e ceill: Simplify for platforms where 'long double' == 'double'.
Bruno Haible <bruno@clisp.org>
parents: 14079
diff changeset
21 #endif
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 /* Specification. */
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 #include <math.h>
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 #include <float.h>
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
14018
ac9f59901721 ceil, trunc, round: Fix gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 13992
diff changeset
28 #undef MIN
ac9f59901721 ceil, trunc, round: Fix gcc warnings.
Bruno Haible <bruno@clisp.org>
parents: 13992
diff changeset
29
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #ifdef USE_LONG_DOUBLE
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 # define FUNC ceill
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 # define DOUBLE long double
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 # define MANT_DIG LDBL_MANT_DIG
13992
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
34 # define MIN LDBL_MIN
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 # define L_(literal) literal##L
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #elif ! defined USE_FLOAT
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 # define FUNC ceil
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 # define DOUBLE double
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 # define MANT_DIG DBL_MANT_DIG
13992
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
40 # define MIN DBL_MIN
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 # define L_(literal) literal
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 #else /* defined USE_FLOAT */
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 # define FUNC ceilf
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 # define DOUBLE float
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 # define MANT_DIG FLT_MANT_DIG
13992
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
46 # define MIN FLT_MIN
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 # define L_(literal) literal##f
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 #endif
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49
13992
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
50 /* -0.0. See minus-zero.h. */
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
51 #if defined __hpux || defined __sgi || defined __ICC
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
52 # define MINUS_ZERO (-MIN * MIN)
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
53 #else
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
54 # define MINUS_ZERO L_(-0.0)
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
55 #endif
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
56
16506
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
57 /* 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
58 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
59 #ifdef _MSC_VER
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
60 # pragma fenv_access (off)
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
61 #endif
fa4e9b981eb4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16201
diff changeset
62
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 /* 2^(MANT_DIG-1). */
9313
59fc463c9868 Fix type of TWO_MANT_DIG.
Bruno Haible <bruno@clisp.org>
parents: 9309
diff changeset
64 static const DOUBLE TWO_MANT_DIG =
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 /* Assume MANT_DIG <= 5 * 31.
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 Use the identity
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 n = floor(n/5) + floor((n+1)/5) + ... + floor((n+4)/5). */
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 (DOUBLE) (1U << ((MANT_DIG - 1) / 5))
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 * (DOUBLE) (1U << ((MANT_DIG - 1 + 1) / 5))
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 * (DOUBLE) (1U << ((MANT_DIG - 1 + 2) / 5))
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 * (DOUBLE) (1U << ((MANT_DIG - 1 + 3) / 5))
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 * (DOUBLE) (1U << ((MANT_DIG - 1 + 4) / 5));
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 DOUBLE
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 FUNC (DOUBLE x)
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 {
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 /* The use of 'volatile' guarantees that excess precision bits are dropped
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 at each addition step and before the following comparison at the caller's
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 site. It is necessary on x86 systems where double-floats are not IEEE
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 compliant by default, to avoid that the results become platform and compiler
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 option dependent. 'volatile' is a portable alternative to gcc's
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 -ffloat-store option. */
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 volatile DOUBLE y = x;
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 volatile DOUBLE z = y;
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 if (z > L_(0.0))
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 {
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents: 9313
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: 9313
diff changeset
89 if (z < TWO_MANT_DIG)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
90 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
91 /* Round to the next integer (nearest or up or down, doesn't matter). */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
92 z += TWO_MANT_DIG;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
93 z -= TWO_MANT_DIG;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
94 /* Enforce rounding up. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
95 if (z < y)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
96 z += L_(1.0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
97 }
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 }
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
99 else if (z < L_(0.0))
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
100 {
13992
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
101 /* For -1 < x < 0, return -0.0 regardless of the current rounding
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
102 mode. */
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
103 if (z > L_(-1.0))
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
104 z = MINUS_ZERO;
9335
5f9727c11975 Fix incorrect rounding of ceil, ceilf, ceill in some cases. Add new test.
Bruno Haible <bruno@clisp.org>
parents: 9313
diff changeset
105 /* Avoid rounding errors for values near -2^k, where k >= MANT_DIG-1. */
13992
749c72ade953 ceil: Implement result sign according to IEEE 754.
Bruno Haible <bruno@clisp.org>
parents: 12559
diff changeset
106 else if (z > - TWO_MANT_DIG)
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
107 {
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
108 /* Round to the next integer (nearest or up or down, doesn't matter). */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
109 z -= TWO_MANT_DIG;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
110 z += TWO_MANT_DIG;
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
111 /* Enforce rounding up. */
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
112 if (z < y)
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
113 z += L_(1.0);
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9335
diff changeset
114 }
9295
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 }
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116 return z;
a19e5992f6f0 New module 'ceilf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 }