annotate lib/cbrtf.c @ 17363:5a51fb7777a9

sys_select, sys_time: port 2013-01-30 Solaris 2.6 fix to Cygwin Problem reported by Marco Atzeri in <http://lists.gnu.org/archive/html/bug-gnulib/2013-03/msg00000.html>. * lib/sys_select.in.h [HAVE_SYS_SELECT_H && _CYGWIN_SYS_TIME_H]: Simply delegate to the system <sys/select.h> in this case too. Also, pay attention to _GL_SYS_SELECT_H_REDIRECT_FROM_SYS_TIME_H only if OSF/1, since otherwise Cygwin breaks, and it doesn't seem to be needed on Solaris either. * lib/sys_time.in.h [_CYGWIN_SYS_TIME_H]: Simply delgate to the system <sys/time.h> in this case.
author Paul Eggert <eggert@cs.ucla.edu>
date Tue, 19 Mar 2013 09:08:47 -0700
parents e542fd46ad6f
children 344018b6e5d7
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16534
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Compute cubic root of float value.
17249
e542fd46ad6f maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents: 16693
diff changeset
2 Copyright (C) 1997, 2012-2013 Free Software Foundation, Inc.
16534
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 Contributed by Dirk Alboth <dirka@uni-paderborn.de> and
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 Ulrich Drepper <drepper@cygnus.com>, 1997.
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 This program is free software: you can redistribute it and/or modify
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 it under the terms of the GNU General Public License as published by
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 (at your option) any later version.
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 This program is distributed in the hope that it will be useful,
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 GNU General Public License for more details.
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #include <config.h>
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 /* Specification. */
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #include <math.h>
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24
16693
55c4c6aa19f4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16534
diff changeset
25 /* MSVC with option -fp:strict refuses to compile constant initializers that
55c4c6aa19f4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16534
diff changeset
26 contain floating-point operations. Pacify this compiler. */
55c4c6aa19f4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16534
diff changeset
27 #ifdef _MSC_VER
55c4c6aa19f4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16534
diff changeset
28 # pragma fenv_access (off)
55c4c6aa19f4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16534
diff changeset
29 #endif
55c4c6aa19f4 Avoid compilation errors with MSVC option -fp:strict.
Bruno Haible <bruno@clisp.org>
parents: 16534
diff changeset
30
16534
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* Code based on glibc/sysdeps/ieee754/flt-32/s_cbrtf.c. */
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 #define CBRT2 1.2599210498948731648 /* 2^(1/3) */
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #define SQR_CBRT2 1.5874010519681994748 /* 2^(2/3) */
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 static const double factor[5] =
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 {
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 1.0 / SQR_CBRT2,
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 1.0 / CBRT2,
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 1.0,
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 CBRT2,
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 SQR_CBRT2
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 };
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 float
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 cbrtf (float x)
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 {
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 if (isfinite (x) && x != 0.0f)
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 {
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 float xm, ym, u, t2;
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 int xe;
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
54 /* Reduce X. XM now is an range 1.0 to 0.5. */
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 xm = frexpf (fabsf (x), &xe);
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
57 u = (0.492659620528969547
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
58 + (0.697570460207922770 - 0.191502161678719066 * xm) * xm);
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
59
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
60 t2 = u * u * u;
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 ym = u * (t2 + 2.0 * xm) / (2.0 * t2 + xm) * factor[2 + xe % 3];
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 return ldexpf (x > 0.0 ? ym : -ym, xe / 3);
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
65 }
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
66 else
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
67 return x + x;
f2d8c70a9f81 New module 'cbrtf'.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
68 }