Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(85816)

Side by Side Diff: Modules/mathmodule.c

Issue 23670: Modifications to support iOS as a development platform
Patch Set: Created 3 years, 8 months ago
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Modules/makesetup ('k') | Modules/posixmodule.c » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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 #ifdef __APPLE__
59 # include "TargetConditionals.h"
60 #endif /* __APPLE__ */
57 61
58 /* 62 /*
59 sin(pi*x), giving accurate results for all finite x (especially x 63 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 64 integral or close to an integer). This is here for use in the
61 reflection formula for the gamma function. It conforms to IEEE 65 reflection formula for the gamma function. It conforms to IEEE
62 754-2008 for finite arguments, but not for infinities or nans. 66 754-2008 for finite arguments, but not for infinities or nans.
63 */ 67 */
64 68
65 static const double pi = 3.141592653589793238462643383279502884197; 69 static const double pi = 3.141592653589793238462643383279502884197;
66 static const double sqrtpi = 1.772453850905516027298167483341145182798; 70 static const double sqrtpi = 1.772453850905516027298167483341145182798;
(...skipping 1735 matching lines...) Expand 10 before | Expand all | Expand 10 after
1802 return NULL; 1806 return NULL;
1803 x = PyFloat_AsDouble(ox); 1807 x = PyFloat_AsDouble(ox);
1804 y = PyFloat_AsDouble(oy); 1808 y = PyFloat_AsDouble(oy);
1805 if ((x == -1.0 || y == -1.0) && PyErr_Occurred()) 1809 if ((x == -1.0 || y == -1.0) && PyErr_Occurred())
1806 return NULL; 1810 return NULL;
1807 /* hypot(x, +/-Inf) returns Inf, even if x is a NaN. */ 1811 /* hypot(x, +/-Inf) returns Inf, even if x is a NaN. */
1808 if (Py_IS_INFINITY(x)) 1812 if (Py_IS_INFINITY(x))
1809 return PyFloat_FromDouble(fabs(x)); 1813 return PyFloat_FromDouble(fabs(x));
1810 if (Py_IS_INFINITY(y)) 1814 if (Py_IS_INFINITY(y))
1811 return PyFloat_FromDouble(fabs(y)); 1815 return PyFloat_FromDouble(fabs(y));
1816 #if TARGET_OS_IPHONE
1817 /* hypot(x, +/-NaN) returns NaN.
1818 Most libc implementations get this right, but for some reason,
1819 the iOS device implementation doesn't.
1820 */
1821 if (Py_IS_NAN(x))
1822 return PyFloat_FromDouble(fabs(x));
1823 if (Py_IS_NAN(y))
1824 return PyFloat_FromDouble(fabs(y));
1825 #endif
1812 errno = 0; 1826 errno = 0;
1813 PyFPE_START_PROTECT("in math_hypot", return 0); 1827 PyFPE_START_PROTECT("in math_hypot", return 0);
1814 r = hypot(x, y); 1828 r = hypot(x, y);
1815 PyFPE_END_PROTECT(r); 1829 PyFPE_END_PROTECT(r);
1816 if (Py_IS_NAN(r)) { 1830 if (Py_IS_NAN(r)) {
1817 if (!Py_IS_NAN(x) && !Py_IS_NAN(y)) 1831 if (!Py_IS_NAN(x) && !Py_IS_NAN(y))
1818 errno = EDOM; 1832 errno = EDOM;
1819 else 1833 else
1820 errno = 0; 1834 errno = 0;
1821 } 1835 }
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
2145 PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI)); 2159 PyModule_AddObject(m, "pi", PyFloat_FromDouble(Py_MATH_PI));
2146 PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E)); 2160 PyModule_AddObject(m, "e", PyFloat_FromDouble(Py_MATH_E));
2147 PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf())); 2161 PyModule_AddObject(m, "inf", PyFloat_FromDouble(m_inf()));
2148 #if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN) 2162 #if !defined(PY_NO_SHORT_FLOAT_REPR) || defined(Py_NAN)
2149 PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan())); 2163 PyModule_AddObject(m, "nan", PyFloat_FromDouble(m_nan()));
2150 #endif 2164 #endif
2151 2165
2152 finally: 2166 finally:
2153 return m; 2167 return m;
2154 } 2168 }
OLDNEW
« no previous file with comments | « Modules/makesetup ('k') | Modules/posixmodule.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+