1919 * ====================================================
2020 */
2121
22+ #if !defined(HAVE_ACOSH ) || !defined(HAVE_ASINH )
2223static const double ln2 = 6.93147180559945286227E-01 ;
23- static const double two_pow_m28 = 3.7252902984619141E-09 ; /* 2**-28 */
2424static const double two_pow_p28 = 268435456.0 ; /* 2**28 */
25- #ifndef Py_NAN
25+ #endif
26+ #if !defined(HAVE_ASINH ) || !defined(HAVE_ATANH )
27+ static const double two_pow_m28 = 3.7252902984619141E-09 ; /* 2**-28 */
28+ #endif
29+ #if !defined(HAVE_ATANH ) && !defined(Py_NAN )
2630static const double zero = 0.0 ;
2731#endif
2832
33+
34+ #ifndef HAVE_ACOSH
2935/* acosh(x)
3036 * Method :
3137 * Based on
@@ -59,23 +65,25 @@ _Py_acosh(double x)
5965 return x + x ;
6066 }
6167 else {
62- return log (x )+ ln2 ; /* acosh(huge)=log(2x) */
68+ return log (x ) + ln2 ; /* acosh(huge)=log(2x) */
6369 }
6470 }
6571 else if (x == 1. ) {
6672 return 0.0 ; /* acosh(1) = 0 */
6773 }
6874 else if (x > 2. ) { /* 2 < x < 2**28 */
69- double t = x * x ;
70- return log (2.0 * x - 1.0 / (x + sqrt (t - 1.0 )));
75+ double t = x * x ;
76+ return log (2.0 * x - 1.0 / (x + sqrt (t - 1.0 )));
7177 }
7278 else { /* 1 < x <= 2 */
7379 double t = x - 1.0 ;
74- return m_log1p (t + sqrt (2.0 * t + t * t ));
80+ return m_log1p (t + sqrt (2.0 * t + t * t ));
7581 }
7682}
83+ #endif /* HAVE_ACOSH */
7784
7885
86+ #ifndef HAVE_ASINH
7987/* asinh(x)
8088 * Method :
8189 * Based on
@@ -100,10 +108,10 @@ _Py_asinh(double x)
100108 return x ; /* return x inexact except 0 */
101109 }
102110 if (absx > two_pow_p28 ) { /* |x| > 2**28 */
103- w = log (absx )+ ln2 ;
111+ w = log (absx ) + ln2 ;
104112 }
105113 else if (absx > 2.0 ) { /* 2 < |x| < 2**28 */
106- w = log (2.0 * absx + 1.0 / (sqrt (x * x + 1.0 ) + absx ));
114+ w = log (2.0 * absx + 1.0 / (sqrt (x * x + 1.0 ) + absx ));
107115 }
108116 else { /* 2**-28 <= |x| < 2= */
109117 double t = x * x ;
@@ -112,7 +120,10 @@ _Py_asinh(double x)
112120 return copysign (w , x );
113121
114122}
123+ #endif /* HAVE_ASINH */
124+
115125
126+ #ifndef HAVE_ATANH
116127/* atanh(x)
117128 * Method :
118129 * 1.Reduced x to positive by atanh(-x) = -atanh(x)
@@ -145,7 +156,7 @@ _Py_atanh(double x)
145156#ifdef Py_NAN
146157 return Py_NAN ;
147158#else
148- return x / zero ;
159+ return x / zero ;
149160#endif
150161 }
151162 if (absx < two_pow_m28 ) { /* |x| < 2**-28 */
@@ -160,7 +171,10 @@ _Py_atanh(double x)
160171 }
161172 return copysign (t , x );
162173}
174+ #endif /* HAVE_ATANH */
175+
163176
177+ #ifndef HAVE_EXPM1
164178/* Mathematically, expm1(x) = exp(x) - 1. The expm1 function is designed
165179 to avoid the significant loss of precision that arises from direct
166180 evaluation of the expression exp(x) - 1, for x near 0. */
@@ -186,16 +200,17 @@ _Py_expm1(double x)
186200 else
187201 return exp (x ) - 1.0 ;
188202}
203+ #endif /* HAVE_EXPM1 */
204+
189205
190206/* log1p(x) = log(1+x). The log1p function is designed to avoid the
191207 significant loss of precision that arises from direct evaluation when x is
192208 small. */
193209
194- #ifdef HAVE_LOG1P
195-
196210double
197211_Py_log1p (double x )
198212{
213+ #ifdef HAVE_LOG1P
199214 /* Some platforms supply a log1p function but don't respect the sign of
200215 zero: log1p(-0.0) gives 0.0 instead of the correct result of -0.0.
201216
@@ -208,13 +223,7 @@ _Py_log1p(double x)
208223 else {
209224 return log1p (x );
210225 }
211- }
212-
213226#else
214-
215- double
216- _Py_log1p (double x )
217- {
218227 /* For x small, we use the following approach. Let y be the nearest float
219228 to 1+x, then
220229
@@ -236,7 +245,7 @@ _Py_log1p(double x)
236245 */
237246
238247 double y ;
239- if (fabs (x ) < DBL_EPSILON / 2. ) {
248+ if (fabs (x ) < DBL_EPSILON / 2. ) {
240249 return x ;
241250 }
242251 else if (-0.5 <= x && x <= 1. ) {
@@ -246,12 +255,12 @@ _Py_log1p(double x)
246255 happens, then results from log1p will be inaccurate
247256 for small x. */
248257 y = 1. + x ;
249- return log (y )- ((y - 1. )- x )/ y ;
258+ return log (y ) - ((y - 1. ) - x ) / y ;
250259 }
251260 else {
252261 /* NaNs and infinities should end up here */
253262 return log (1. + x );
254263 }
264+ #endif /* ifdef HAVE_LOG1P */
255265}
256266
257- #endif /* ifdef HAVE_LOG1P */
0 commit comments