annotate lib/exp2l.c @ 17160:72f4bab621be

fts: introduce FTS_VERBATIM This gives clients the option to disable stripping of trailing slashes from input path names during fts_open initialization. The recent change v0.0-7611-g3a9002d that made fts_open strip trailing slashes from input path names had a negative impact on findutils that relies on the old fts_open behavior to implement POSIX requirement that each path operand of the find utility shall be evaluated unaltered as it was provided, including all trailing slash characters. * lib/fts_.h (FTS_VERBATIM): New bit flag. (FTS_OPTIONMASK, FTS_NAMEONLY, FTS_STOP): Adjust. * lib/fts.c (fts_open): Honor it.
author Dmitry V. Levin <ldv@altlinux.org>
date Sun, 18 Nov 2012 04:40:18 +0400
parents 6c0da1a4068d
children e542fd46ad6f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16620
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Exponential base 2 function.
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
2 Copyright (C) 2011-2012 Free Software Foundation, Inc.
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 #include <config.h>
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 /* Specification. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <math.h>
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 #if HAVE_SAME_LONG_DOUBLE_AS_DOUBLE
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 long double
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 exp2l (long double x)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 {
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 return exp2 (x);
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 }
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 #else
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 # include <float.h>
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 /* gl_expl_table[i] = exp((i - 128) * log(2)/256). */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 extern const long double gl_expl_table[257];
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 /* Best possible approximation of log(2) as a 'long double'. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #define LOG2 0.693147180559945309417232121458176568075L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 /* Best possible approximation of 1/log(2) as a 'long double'. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 #define LOG2_INVERSE 1.44269504088896340735992468100189213743L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 /* Best possible approximation of log(2)/256 as a 'long double'. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 #define LOG2_BY_256 0.00270760617406228636491106297444600221904L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* Best possible approximation of 256/log(2) as a 'long double'. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 #define LOG2_BY_256_INVERSE 369.329930467574632284140718336484387181L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 long double
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 exp2l (long double x)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 {
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 /* exp2(x) = exp(x*log(2)).
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 If we would compute it like this, there would be rounding errors for
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 integer or near-integer values of x. To avoid these, we inline the
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 algorithm for exp(), and the multiplication with log(2) cancels a
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56 division by log(2). */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 if (isnanl (x))
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59 return x;
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61 if (x > (long double) LDBL_MAX_EXP)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 /* x > LDBL_MAX_EXP
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 hence exp2(x) > 2^LDBL_MAX_EXP, overflows to Infinity. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 return HUGE_VALL;
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 if (x < (long double) (LDBL_MIN_EXP - 1 - LDBL_MANT_DIG))
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 /* x < (LDBL_MIN_EXP - 1 - LDBL_MANT_DIG)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 hence exp2(x) < 2^(LDBL_MIN_EXP-1-LDBL_MANT_DIG),
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
69 underflows to zero. */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70 return 0.0L;
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72 /* Decompose x into
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 x = n + m/256 + y/log(2)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 where
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75 n is an integer,
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 m is an integer, -128 <= m <= 128,
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77 y is a number, |y| <= log(2)/512 + epsilon = 0.00135...
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78 Then
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 exp2(x) = 2^n * exp(m * log(2)/256) * exp(y)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 The first factor is an ldexpl() call.
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 The second factor is a table lookup.
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82 The third factor is computed
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 - either as sinh(y) + cosh(y)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
84 where sinh(y) is computed through the power series:
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
85 sinh(y) = y + y^3/3! + y^5/5! + ...
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
86 and cosh(y) is computed as hypot(1, sinh(y)),
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
87 - or as exp(2*z) = (1 + tanh(z)) / (1 - tanh(z))
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
88 where z = y/2
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
89 and tanh(z) is computed through its power series:
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
90 tanh(z) = z
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
91 - 1/3 * z^3
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
92 + 2/15 * z^5
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
93 - 17/315 * z^7
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
94 + 62/2835 * z^9
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
95 - 1382/155925 * z^11
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
96 + 21844/6081075 * z^13
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
97 - 929569/638512875 * z^15
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
98 + ...
16651
6c0da1a4068d Fix some comments.
Bruno Haible <bruno@clisp.org>
parents: 16620
diff changeset
99 Since |z| <= log(2)/1024 < 0.0007, the relative contribution of the
6c0da1a4068d Fix some comments.
Bruno Haible <bruno@clisp.org>
parents: 16620
diff changeset
100 z^13 term is < 0.0007^12 < 2^-120 <= 2^-LDBL_MANT_DIG, therefore we
6c0da1a4068d Fix some comments.
Bruno Haible <bruno@clisp.org>
parents: 16620
diff changeset
101 can truncate the series after the z^11 term. */
16620
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
102
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
103 {
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
104 long double nm = roundl (x * 256.0L); /* = 256 * n + m */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
105 long double z = (x * 256.0L - nm) * (LOG2_BY_256 * 0.5L);
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
106
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
107 /* Coefficients of the power series for tanh(z). */
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
108 #define TANH_COEFF_1 1.0L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
109 #define TANH_COEFF_3 -0.333333333333333333333333333333333333334L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
110 #define TANH_COEFF_5 0.133333333333333333333333333333333333334L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
111 #define TANH_COEFF_7 -0.053968253968253968253968253968253968254L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
112 #define TANH_COEFF_9 0.0218694885361552028218694885361552028218L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
113 #define TANH_COEFF_11 -0.00886323552990219656886323552990219656886L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
114 #define TANH_COEFF_13 0.00359212803657248101692546136990581435026L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
115 #define TANH_COEFF_15 -0.00145583438705131826824948518070211191904L
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
116
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
117 long double z2 = z * z;
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
118 long double tanh_z =
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
119 (((((TANH_COEFF_11
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
120 * z2 + TANH_COEFF_9)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
121 * z2 + TANH_COEFF_7)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
122 * z2 + TANH_COEFF_5)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
123 * z2 + TANH_COEFF_3)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
124 * z2 + TANH_COEFF_1)
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
125 * z;
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
126
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
127 long double exp_y = (1.0L + tanh_z) / (1.0L - tanh_z);
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
128
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
129 int n = (int) roundl (nm * (1.0L / 256.0L));
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
130 int m = (int) nm - 256 * n;
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
131
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
132 return ldexpl (gl_expl_table[128 + m] * exp_y, n);
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
133 }
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
134 }
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
135
4a578c3945b8 New module 'exp2l'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
136 #endif