• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

The MinGW.org Windows System Libraries


Commit MetaInfo

Revisãoaae1b310df39d2d33a3b42dcc8e159ec933f6f3d (tree)
Hora2013-06-08 08:18:37
AutorEarnie Boyd <earnie@user...>
CommiterEarnie Boyd

Mensagem de Log

Merge changes from repository.

Mudança Sumário

Diff

--- a/ChangeLog
+++ b/ChangeLog
@@ -18,6 +18,20 @@
1818 * include/time.h: Correct typos. Add MSVCRT_VERSION >= 800 guard for
1919 _CRTALIAS of _wctime.
2020
21+2013-06-05 Keith Marshall <keithmarshall@users.sourceforge.net>
22+
23+ Provide more robust inverse hyperbolic sine functions.
24+
25+ * src/libcrt/math/asinh.c: Rewritten; it now provides a generic
26+ implementation for asinh(), asinhf(), and asinhl() functions; thus...
27+ * src/libcrt/math/asinhf.c src/libcrt/math/asinhl.c: ...are obsolete;
28+ delete them.
29+
30+ * Makefile.in (math_SOURCES): Remove references for asinh[fl].c
31+ (libmingwex_a_OBJECTS): Add explicit references to create associated
32+ object files, from the common generic source, together with build
33+ rules to compile them.
34+
2135 2013-06-05 Mark <mabrand@users.sourceforge.net>
2236
2337 * include/shlobj.h (SHGetFolderPath): Correct typo for UNICODE define.
--- a/Makefile.in
+++ b/Makefile.in
@@ -365,8 +365,6 @@ math_SOURCES := \
365365 $(SRCDIR)/acosl.c \
366366 $(SRCDIR)/asinf.c \
367367 $(SRCDIR)/asinh.c \
368- $(SRCDIR)/asinhf.c \
369- $(SRCDIR)/asinhl.c \
370368 $(SRCDIR)/asinl.c \
371369 $(SRCDIR)/atan2f.c \
372370 $(SRCDIR)/atan2l.c \
@@ -624,6 +622,10 @@ libmingwex_a_SOURCES := \
624622 libmingwex_a_OBJECTS := $(libmingwex_a_SOURCES:.c=.o)
625623 libmingwex_a_OBJECTS := $(libmingwex_a_OBJECTS:.S=.o)
626624
625+SRCDIR := src/libcrt/math
626+libmingwex_a_OBJECTS := $(libmingwex_a_OBJECTS) $(SRCDIR)/asinhl.o
627+libmingwex_a_OBJECTS := $(libmingwex_a_OBJECTS) $(SRCDIR)/asinhf.o
628+
627629 SRCDIR := misc/src/libdinput
628630 libdinput_a_SOURCES := \
629631 $(SRCDIR)/dinput_joy.c \
@@ -745,6 +747,15 @@ lib%.a: src/lib%/%.o
745747 $(MKDIR_P) $(@D)
746748 $(CC) -c $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
747749
750+SRCDIR := src/libcrt/math
751+$(SRCDIR)/%f.o: $(SRCDIR)/%.c
752+ $(MKDIR_P) $(@D)
753+ $(CC) -c -D FUNCTION=$(@F:.o=) $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
754+
755+$(SRCDIR)/%l.o: $(SRCDIR)/%.c
756+ $(MKDIR_P) $(@D)
757+ $(CC) -c -D FUNCTION=$(@F:.o=) $(CPPFLAGS) $(ALL_CFLAGS) -o $@ $<
758+
748759 SRCDIR := src/libcrt/crt
749760 $(SRCDIR)/crt2.o $(SRCDIR)/dllcrt2.o:
750761 $(MKDIR_P) $(@D)
@@ -1422,4 +1433,4 @@ clean-dist-w32api:
14221433 rm -rf dist/w32api/
14231434
14241435 clean-dist-wsl:
1425- rm -rf dist/wsl/
\ No newline at end of file
1436+ rm -rf dist/wsl/
--- a/src/libcrt/math/asinh.c
+++ b/src/libcrt/math/asinh.c
@@ -20,32 +20,127 @@
2020 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
2121 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2222 * DEALINGS IN THE SOFTWARE.
23+ *
24+ *
25+ * Implemented 2013 by Keith Marshall <keithmarshall@users.sourceforge.net>
26+ * Copyright assigned by the author to the MinGW.org project.
27+ *
28+ * This is a generic implementation for all of the asinh(), asinhl(),
29+ * and asinhf() functions; each is to be compiled separately, i.e.
30+ *
31+ * gcc -D FUNCTION=asinh -o asinh.o asinh.c
32+ * gcc -D FUNCTION=asinhl -o asinhl.o asinh.c
33+ * gcc -D FUNCTION=asinhf -o asinhf.o asinh.c
34+ *
2335 */
2436 #include <math.h>
25-#include <errno.h>
26-#include "fastmath.h"
2737
28- /* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */
29-double asinh(double x)
30-{
31- double z;
32- if (!isfinite (x))
33- return x;
34- z = fabs (x);
35-
36- /* Avoid setting FPU underflow exception flag in x * x. */
37-#if 0
38- if ( z < 0x1p-32)
39- return x;
38+#ifndef FUNCTION
39+/* If user neglected to specify it, the default compilation is for
40+ * the asinh() function.
41+ */
42+# define FUNCTION asinh
4043 #endif
4144
42- /* Use log1p to avoid cancellation with small x. Put
43- x * x in denom, so overflow is harmless.
44- asinh(x) = log1p (x + sqrt (x * x + 1.0) - 1.0)
45- = log1p (x + x * x / (sqrt (x * x + 1.0) + 1.0)) */
45+#define argtype_asinh double
46+#define argtype_asinhl long double
47+#define argtype_asinhf float
4648
47- z = __fast_log1p (z + z * z / (__fast_sqrt (z * z + 1.0) + 1.0));
49+#define PASTE(PREFIX,SUFFIX) PREFIX##SUFFIX
50+#define mapname(PREFIX,SUFFIX) PASTE(PREFIX,SUFFIX)
4851
49- return ( x > 0.0 ? z : -z);
50-}
52+#define ARGTYPE(FUNCTION) PASTE(argtype_,FUNCTION)
53+#define ARGCAST(VALUE) mapname(argcast_,FUNCTION)(VALUE)
54+
55+#define argcast_asinh(VALUE) VALUE
56+#define argcast_asinhl(VALUE) PASTE(VALUE,L)
57+#define argcast_asinhf(VALUE) PASTE(VALUE,F)
5158
59+#define mapfunc(NAME) mapname(mapfunc_,FUNCTION)(NAME)
60+
61+#define mapfunc_asinh(NAME) NAME
62+#define mapfunc_asinhl(NAME) PASTE(NAME,l)
63+#define mapfunc_asinhf(NAME) PASTE(NAME,f)
64+
65+/* Prefer fast versions of mathematical functions.
66+ */
67+#include "fastmath.h"
68+
69+#define log __fast_log
70+#define log1p __fast_log1p
71+#define sqrt __fast_sqrt
72+
73+/* Define the generic function implementation.
74+ */
75+ARGTYPE(FUNCTION) FUNCTION( ARGTYPE(FUNCTION) x )
76+{
77+ if( isfinite(x) )
78+ {
79+ /* For all finite values of x, we may compute asinh(x) in terms of
80+ * the magnitude of x...
81+ */
82+ ARGTYPE(FUNCTION) h, z;
83+ if( (z = mapfunc(fabs)( x )) > ARGCAST(1.0) )
84+ {
85+ /* When z is greater than 1.0, there is a possibility of overflow
86+ * in the computation of z * z; this would propagate to the result
87+ * of computing sqrt( 1.0 + z * z ), even when the ultimate result
88+ * should be representable. Thus, we adopt a transformation based
89+ * on hypot(), which cannot overflow, viz.:
90+ *
91+ * sqrt( 1.0 + z * z )
92+ *
93+ * is equivalent to
94+ *
95+ * z * sqrt( 1.0 + (1.0 / z) * (1.0 / z) )
96+ */
97+ h = ARGCAST(1.0) / z;
98+ h = z * mapfunc(sqrt)( ARGCAST(1.0) + h * h );
99+ }
100+ else
101+ { /* z is less that 1.0: we may safely compute z * z without fear of
102+ * overflow; it may underflow to zero, in which case we may simply
103+ * ignore the effect, as it is insignificant.
104+ */
105+ h = mapfunc(sqrt)( ARGCAST(1.0) + z * z );
106+ }
107+
108+ /* Now, we may compute the absolute value of the inverse hyperbolic
109+ * sine function, according to its analytical definition:
110+ *
111+ * arsinh( z ) = log( z + sqrt( 1.0 + z * z ) )
112+ *
113+ * or, since we've already computed h = sqrt( 1.0 + z * z ):
114+ *
115+ * arsinh( z ) = log( z + h )
116+ *
117+ * We may note that, in spite of our efforts to avoid overflow in the
118+ * computation of h, this expression for arsinh(z) remains vulnerable to
119+ * overflow as z approaches the representable limit of finite floating
120+ * point values, even when the ultimate result is both representable and
121+ * computable. We may further note that h >= z is always true, with h
122+ * approaching an asymptotic minimum of 1.0, as z becomes vanishingly
123+ * small, while h becomes approximately equal to z as z becomes very
124+ * large; thus we may transform the expression to:
125+ *
126+ * arsinh( z ) = log( z / h + 1.0 ) + log( h )
127+ *
128+ * or its equivalent representation:
129+ *
130+ * arsinh( z ) = log1p( z / h ) + log( h )
131+ *
132+ * which is computable, without overflow, for all finite values of z
133+ * with corresponding finite values of h for which the logarithm is
134+ * computable.
135+ *
136+ * Finally, we note that the ultimate result has the same sign as the
137+ * original value of x, with magnitude as computed by the preceding
138+ * expression; thus...
139+ */
140+ return mapfunc(copysign)( mapfunc(log1p)( z / h ) + mapfunc(log)( h ), x );
141+ }
142+ /* If we get to here, x was infinite; we can do no more than return an
143+ * equivalent infinite result.
144+ */
145+ return x;
146+}
--- a/src/libcrt/math/asinhf.c
+++ /dev/null
@@ -1,51 +0,0 @@
1-/**
2- * @file asinhf.c
3- * Copyright 2012, 2013 MinGW.org project
4- *
5- * Permission is hereby granted, free of charge, to any person obtaining a
6- * copy of this software and associated documentation files (the "Software"),
7- * to deal in the Software without restriction, including without limitation
8- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9- * and/or sell copies of the Software, and to permit persons to whom the
10- * Software is furnished to do so, subject to the following conditions:
11- *
12- * The above copyright notice and this permission notice (including the next
13- * paragraph) shall be included in all copies or substantial portions of the
14- * Software.
15- *
16- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22- * DEALINGS IN THE SOFTWARE.
23- */
24-#include <math.h>
25-#include <errno.h>
26-#include "fastmath.h"
27-
28- /* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */
29-float asinhf(float x)
30-{
31- float z;
32- if (!isfinite (x))
33- return x;
34- z = fabsf (x);
35-
36- /* Avoid setting FPU underflow exception flag in x * x. */
37-#if 0
38- if ( z < 0x1p-32)
39- return x;
40-#endif
41-
42-
43- /* Use log1p to avoid cancellation with small x. Put
44- x * x in denom, so overflow is harmless.
45- asinh(x) = log1p (x + sqrt (x * x + 1.0) - 1.0)
46- = log1p (x + x * x / (sqrt (x * x + 1.0) + 1.0)) */
47-
48- z = __fast_log1p (z + z * z / (__fast_sqrt (z * z + 1.0) + 1.0));
49-
50- return ( x > 0.0 ? z : -z);
51-}
--- a/src/libcrt/math/asinhl.c
+++ /dev/null
@@ -1,51 +0,0 @@
1-/**
2- * @file asinhl.c
3- * Copyright 2012, 2013 MinGW.org project
4- *
5- * Permission is hereby granted, free of charge, to any person obtaining a
6- * copy of this software and associated documentation files (the "Software"),
7- * to deal in the Software without restriction, including without limitation
8- * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9- * and/or sell copies of the Software, and to permit persons to whom the
10- * Software is furnished to do so, subject to the following conditions:
11- *
12- * The above copyright notice and this permission notice (including the next
13- * paragraph) shall be included in all copies or substantial portions of the
14- * Software.
15- *
16- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21- * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22- * DEALINGS IN THE SOFTWARE.
23- */
24-#include <math.h>
25-#include <errno.h>
26-#include "fastmath.h"
27-
28- /* asinh(x) = copysign(log(fabs(x) + sqrt(x * x + 1.0)), x) */
29-long double asinhl(long double x)
30-{
31- long double z;
32- if (!isfinite (x))
33- return x;
34-
35- z = fabsl (x);
36-
37- /* Avoid setting FPU underflow exception flag in x * x. */
38-#if 0
39- if ( z < 0x1p-32)
40- return x;
41-#endif
42-
43- /* Use log1p to avoid cancellation with small x. Put
44- x * x in denom, so overflow is harmless.
45- asinh(x) = log1p (x + sqrt (x * x + 1.0) - 1.0)
46- = log1p (x + x * x / (sqrt (x * x + 1.0) + 1.0)) */
47-
48- z = __fast_log1pl (z + z * z / (__fast_sqrtl (z * z + 1.0L) + 1.0L));
49-
50- return ( x > 0.0 ? z : -z);
51-}