OLD | NEW |
1 /* Definitions of some C99 math library functions, for those platforms | 1 /* Definitions of some C99 math library functions, for those platforms |
2 that don't implement these functions already. */ | 2 that don't implement these functions already. */ |
3 | 3 |
4 #include "Python.h" | 4 #include "Python.h" |
5 #include <float.h> | 5 #include <float.h> |
6 #include "_math.h" | 6 #include "_math.h" |
| 7 |
| 8 #if defined(__MINGW32__) |
| 9 # define USE_MINGWEX_MATH |
| 10 #endif |
| 11 |
| 12 #ifdef USE_MINGWEX_MATH |
| 13 /* To avoid problems with many MSVCRT implementations we will |
| 14 * use a work-around |
| 15 */ |
| 16 #define MAXLOG 7.09782712893383996843E2 |
| 17 #define MINLOG -7.45133219101941108420E2 |
| 18 |
| 19 static double fake_exp (double x) { |
| 20 if (isnan(x)) { return(x); } |
| 21 if (isinf(x)) { return(x > 0.0 ? x : 0.0); } |
| 22 if (x > MAXLOG) { errno = ERANGE; return(INFINITY); } |
| 23 /* the correct code is to set ERANGE but why windows build bot don't fail ? */ |
| 24 if (x < MINLOG) { errno = ERANGE; return(0.0); } |
| 25 |
| 26 return(exp(x)); |
| 27 } |
| 28 #define exp fake_exp |
| 29 #endif /*def USE_MINGWEX_MATH*/ |
7 | 30 |
8 /* The following copyright notice applies to the original | 31 /* The following copyright notice applies to the original |
9 implementations of acosh, asinh and atanh. */ | 32 implementations of acosh, asinh and atanh. */ |
10 | 33 |
11 /* | 34 /* |
12 * ==================================================== | 35 * ==================================================== |
13 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. | 36 * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. |
14 * | 37 * |
15 * Developed at SunPro, a Sun Microsystems, Inc. business. | 38 * Developed at SunPro, a Sun Microsystems, Inc. business. |
16 * Permission to use, copy, modify, and distribute this | 39 * Permission to use, copy, modify, and distribute this |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
172 For smaller x, we can use a method due to Kahan that achieves close to | 195 For smaller x, we can use a method due to Kahan that achieves close to |
173 full accuracy. | 196 full accuracy. |
174 */ | 197 */ |
175 | 198 |
176 if (fabs(x) < 0.7) { | 199 if (fabs(x) < 0.7) { |
177 double u; | 200 double u; |
178 u = exp(x); | 201 u = exp(x); |
179 if (u == 1.0) | 202 if (u == 1.0) |
180 return x; | 203 return x; |
181 else | 204 else |
| 205 #if 0 |
182 return (u - 1.0) * x / log(u); | 206 return (u - 1.0) * x / log(u); |
| 207 #else |
| 208 { /* avoid precision error */ |
| 209 double r; |
| 210 r = x / log(u); |
| 211 return((u - 1.0) * r); |
| 212 } |
| 213 #endif |
183 } | 214 } |
184 else | 215 else |
| 216 #ifdef USE_MINGWEX_MATH |
| 217 /* to avoid errors with correct fake_exp: |
| 218 expm10211:expm1(-1420.0): expected -1.0, got 'OverflowError' |
| 219 expm10212:expm1(-1450.0): expected -1.0, got 'OverflowError' |
| 220 expm10213:expm1(-1500.0): expected -1.0, got 'OverflowError' |
| 221 expm10214:expm1(-1e+50): expected -1.0, got 'OverflowError' |
| 222 expm10215:expm1(-1.79e+308): expected -1.0, got 'OverflowError' |
| 223 */ |
| 224 if (x < MINLOG) { return(-1.0); } |
| 225 else |
| 226 #endif |
185 return exp(x) - 1.0; | 227 return exp(x) - 1.0; |
186 } | 228 } |
187 | 229 |
188 /* log1p(x) = log(1+x). The log1p function is designed to avoid the | 230 /* log1p(x) = log(1+x). The log1p function is designed to avoid the |
189 significant loss of precision that arises from direct evaluation when x is | 231 significant loss of precision that arises from direct evaluation when x is |
190 small. */ | 232 small. */ |
191 | 233 |
192 #ifdef HAVE_LOG1P | 234 #ifdef HAVE_LOG1P |
193 | 235 |
194 double | 236 double |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
246 y = 1.+x; | 288 y = 1.+x; |
247 return log(y)-((y-1.)-x)/y; | 289 return log(y)-((y-1.)-x)/y; |
248 } | 290 } |
249 else { | 291 else { |
250 /* NaNs and infinities should end up here */ | 292 /* NaNs and infinities should end up here */ |
251 return log(1.+x); | 293 return log(1.+x); |
252 } | 294 } |
253 } | 295 } |
254 | 296 |
255 #endif /* ifdef HAVE_LOG1P */ | 297 #endif /* ifdef HAVE_LOG1P */ |
OLD | NEW |