Merged revisions 59666-59679 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59666 | christian.heimes | 2008-01-02 19:28:32 +0100 (Wed, 02 Jan 2008) | 1 line
Made vs9to8 Unix compatible
........
r59669 | guido.van.rossum | 2008-01-02 20:00:46 +0100 (Wed, 02 Jan 2008) | 2 lines
Patch #1696. Don't attempt to close None in dry-run mode.
........
r59671 | jeffrey.yasskin | 2008-01-03 03:21:52 +0100 (Thu, 03 Jan 2008) | 6 lines
Backport PEP 3141 from the py3k branch to the trunk. This includes r50877 (just
the complex_pow part), r56649, r56652, r56715, r57296, r57302, r57359, r57361,
r57372, r57738, r57739, r58017, r58039, r58040, and r59390, and new
documentation. The only significant difference is that round(x) returns a float
to preserve backward-compatibility. See http://bugs.python.org/issue1689.
........
r59672 | christian.heimes | 2008-01-03 16:41:30 +0100 (Thu, 03 Jan 2008) | 1 line
Issue #1726: Remove Python/atof.c from PCBuild/pythoncore.vcproj
........
r59675 | guido.van.rossum | 2008-01-03 20:12:44 +0100 (Thu, 03 Jan 2008) | 4 lines
Issue #1700, reported by Nguyen Quan Son, fix by Fredruk Lundh:
Regular Expression inline flags not handled correctly for some unicode
characters. (Forward port from 2.5.2.)
........
r59676 | christian.heimes | 2008-01-03 21:23:15 +0100 (Thu, 03 Jan 2008) | 1 line
Added math.isinf() and math.isnan()
........
r59677 | christian.heimes | 2008-01-03 22:14:48 +0100 (Thu, 03 Jan 2008) | 1 line
Some build bots don't compile mathmodule. There is an issue with the long definition of pi and euler
........
r59678 | christian.heimes | 2008-01-03 23:16:32 +0100 (Thu, 03 Jan 2008) | 2 lines
Modified PyImport_Import and PyImport_ImportModule to always use absolute imports by calling __import__ with an explicit level of 0
Added a new API function PyImport_ImportModuleNoBlock. It solves the problem with dead locks when mixing threads and imports
........
r59679 | christian.heimes | 2008-01-03 23:32:26 +0100 (Thu, 03 Jan 2008) | 1 line
Added copysign(x, y) function to the math module
........
diff --git a/Modules/mathmodule.c b/Modules/mathmodule.c
index edf5e9b..8992bae 100644
--- a/Modules/mathmodule.c
+++ b/Modules/mathmodule.c
@@ -133,6 +133,14 @@
"cos(x)\n\nReturn the cosine of x (measured in radians).")
FUNC1(cosh, cosh,
"cosh(x)\n\nReturn the hyperbolic cosine of x.")
+#if defined(MS_WINDOWS) || defined(HAVE_COPYSIGN)
+#ifdef MS_WINDOWS
+FUNC2(copysign, _copysign,
+#else
+FUNC2(copysign, copysign,
+#endif
+ "copysign(x,y)\n\nReturn x with the sign of y.");
+#endif
FUNC1(exp, exp,
"exp(x)\n\nReturn e raised to the power of x.")
FUNC1(fabs, fabs,
@@ -315,9 +323,8 @@
PyDoc_STRVAR(math_log10_doc,
"log10(x) -> the base 10 logarithm of x.");
-/* XXX(nnorwitz): Should we use the platform M_PI or something more accurate
- like: 3.14159265358979323846264338327950288 */
-static const double degToRad = 3.141592653589793238462643383 / 180.0;
+static const double degToRad = Py_MATH_PI / 180.0;
+static const double radToDeg = 180.0 / Py_MATH_PI;
static PyObject *
math_degrees(PyObject *self, PyObject *arg)
@@ -325,7 +332,7 @@
double x = PyFloat_AsDouble(arg);
if (x == -1.0 && PyErr_Occurred())
return NULL;
- return PyFloat_FromDouble(x / degToRad);
+ return PyFloat_FromDouble(x * radToDeg);
}
PyDoc_STRVAR(math_degrees_doc,
@@ -343,12 +350,42 @@
PyDoc_STRVAR(math_radians_doc,
"radians(x) -> converts angle x from degrees to radians");
+static PyObject *
+math_isnan(PyObject *self, PyObject *arg)
+{
+ double x = PyFloat_AsDouble(arg);
+ if (x == -1.0 && PyErr_Occurred())
+ return NULL;
+ return PyBool_FromLong((long)Py_IS_NAN(x));
+}
+
+PyDoc_STRVAR(math_isnan_doc,
+"isnan(x) -> bool\n\
+Checks if float x is not a number (NaN)");
+
+static PyObject *
+math_isinf(PyObject *self, PyObject *arg)
+{
+ double x = PyFloat_AsDouble(arg);
+ if (x == -1.0 && PyErr_Occurred())
+ return NULL;
+ return PyBool_FromLong((long)Py_IS_INFINITY(x));
+}
+
+PyDoc_STRVAR(math_isinf_doc,
+"isinf(x) -> bool\n\
+Checks if float x is infinite (positive or negative)");
+
+
static PyMethodDef math_methods[] = {
{"acos", math_acos, METH_O, math_acos_doc},
{"asin", math_asin, METH_O, math_asin_doc},
{"atan", math_atan, METH_O, math_atan_doc},
{"atan2", math_atan2, METH_VARARGS, math_atan2_doc},
{"ceil", math_ceil, METH_O, math_ceil_doc},
+#if defined(MS_WINDOWS) || defined(HAVE_COPYSIGN)
+ {"copysign", math_copysign, METH_VARARGS, math_copysign_doc},
+#endif
{"cos", math_cos, METH_O, math_cos_doc},
{"cosh", math_cosh, METH_O, math_cosh_doc},
{"degrees", math_degrees, METH_O, math_degrees_doc},
@@ -358,6 +395,8 @@
{"fmod", math_fmod, METH_VARARGS, math_fmod_doc},
{"frexp", math_frexp, METH_O, math_frexp_doc},
{"hypot", math_hypot, METH_VARARGS, math_hypot_doc},
+ {"isinf", math_isinf, METH_O, math_isinf_doc},
+ {"isnan", math_isnan, METH_O, math_isnan_doc},
{"ldexp", math_ldexp, METH_VARARGS, math_ldexp_doc},
{"log", math_log, METH_VARARGS, math_log_doc},
{"log10", math_log10, METH_O, math_log10_doc},
@@ -389,13 +428,13 @@
if (d == NULL)
goto finally;
- if (!(v = PyFloat_FromDouble(atan(1.0) * 4.0)))
+ if (!(v = PyFloat_FromDouble(Py_MATH_PI)))
goto finally;
if (PyDict_SetItemString(d, "pi", v) < 0)
goto finally;
Py_DECREF(v);
- if (!(v = PyFloat_FromDouble(exp(1.0))))
+ if (!(v = PyFloat_FromDouble(Py_MATH_E)))
goto finally;
if (PyDict_SetItemString(d, "e", v) < 0)
goto finally;