OLD | NEW |
1 /* Math module -- standard C math library functions, pi and e */ | 1 /* Math module -- standard C math library functions, pi and e */ |
2 | 2 |
3 /* Here are some comments from Tim Peters, extracted from the | 3 /* Here are some comments from Tim Peters, extracted from the |
4 discussion attached to http://bugs.python.org/issue1640. They | 4 discussion attached to http://bugs.python.org/issue1640. They |
5 describe the general aims of the math module with respect to | 5 describe the general aims of the math module with respect to |
6 special values, IEEE-754 floating-point exceptions, and Python | 6 special values, IEEE-754 floating-point exceptions, and Python |
7 exceptions. | 7 exceptions. |
8 | 8 |
9 These are the "spirit of 754" rules: | 9 These are the "spirit of 754" rules: |
10 | 10 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 standard, including Annex 'F', whenever possible. Where the | 47 standard, including Annex 'F', whenever possible. Where the |
48 standard recommends raising the 'divide-by-zero' or 'invalid' | 48 standard recommends raising the 'divide-by-zero' or 'invalid' |
49 floating-point exceptions, Python should raise a ValueError. Where | 49 floating-point exceptions, Python should raise a ValueError. Where |
50 the standard recommends raising 'overflow', Python should raise an | 50 the standard recommends raising 'overflow', Python should raise an |
51 OverflowError. In all other circumstances a value should be | 51 OverflowError. In all other circumstances a value should be |
52 returned. | 52 returned. |
53 */ | 53 */ |
54 | 54 |
55 #include "Python.h" | 55 #include "Python.h" |
56 #include "_math.h" | 56 #include "_math.h" |
| 57 |
| 58 #if defined(__MINGW32__) |
| 59 # define USE_MINGWEX_MATH |
| 60 #endif |
| 61 |
| 62 #ifdef USE_MINGWEX_MATH |
| 63 /* Since ldexp() is broken on many MSVCRT implementations and mingwex |
| 64 * library provide a long double version we will use it as work-around. |
| 65 * As example broken ldexp return for ldexp(1., INT_MAX) 0(zero) instead inf. |
| 66 * With this work-around math test testLdexp pass. |
| 67 */ |
| 68 static double fake_ldexp (double x, int expn) { return ldexpl (x, expn); } |
| 69 #define ldexp fake_ldexp |
| 70 |
| 71 /* Since pow() is broken on many MSVCRT implementations and library |
| 72 * mingwex provide a long double version we will use it as work-around. |
| 73 * As example broken pow return for pow(132.97585637020967, 126.95117632943295) |
| 74 * 4.1252919849060512e+269 instead 4.1252919849057403e+269. |
| 75 * With this work-around math test test_mtestfile pass for gamma. |
| 76 */ |
| 77 static double fake_pow (double x, double y) { return powl (x, y); } |
| 78 #define pow fake_pow |
| 79 |
| 80 #endif /*def USE_MINGWEX_MATH*/ |
57 | 81 |
58 /* | 82 /* |
59 sin(pi*x), giving accurate results for all finite x (especially x | 83 sin(pi*x), giving accurate results for all finite x (especially x |
60 integral or close to an integer). This is here for use in the | 84 integral or close to an integer). This is here for use in the |
61 reflection formula for the gamma function. It conforms to IEEE | 85 reflection formula for the gamma function. It conforms to IEEE |
62 754-2008 for finite arguments, but not for infinities or nans. | 86 754-2008 for finite arguments, but not for infinities or nans. |
63 */ | 87 */ |
64 | 88 |
65 static const double pi = 3.141592653589793238462643383279502884197; | 89 static const double pi = 3.141592653589793238462643383279502884197; |
66 static const double sqrtpi = 1.772453850905516027298167483341145182798; | 90 static const double sqrtpi = 1.772453850905516027298167483341145182798; |
(...skipping 1930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1997 m = PyModule_Create(&mathmodule); | 2021 m = PyModule_Create(&mathmodule); |
1998 if (m == NULL) | 2022 if (m == NULL) |
1999 goto finally; | 2023 goto finally; |
2000 | 2024 |
2001 PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI)); | 2025 PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI)); |
2002 PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E)); | 2026 PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E)); |
2003 | 2027 |
2004 finally: | 2028 finally: |
2005 return m; | 2029 return m; |
2006 } | 2030 } |
OLD | NEW |