Index: Lib/test/test_math.py =================================================================== --- Lib/test/test_math.py (revision 66056) +++ Lib/test/test_math.py (working copy) @@ -511,6 +511,9 @@ self.ftest('log(32,2)', math.log(32,2), 5) self.ftest('log(10**40, 10)', math.log(10**40, 10), 40) self.ftest('log(10**40, 10**20)', math.log(10**40, 10**20), 2) + self.ftest('log(1000, 10)', math.log(1000, 10), 3) + self.ftest('log(1000, 10.0)', math.log(1000, 10.0), 3) + self.ftest('log(1000, 10L)', math.log(1000, 10L), 3) self.assertEquals(math.log(INF), INF) self.assertRaises(ValueError, math.log, NINF) self.assert_(math.isnan(math.log(NAN))) Index: Modules/mathmodule.c =================================================================== --- Modules/mathmodule.c (revision 66056) +++ Modules/mathmodule.c (working copy) @@ -762,6 +762,30 @@ if (num == NULL || base == NULL) return num; + /* Use log10 when called with 10 as base to increase accuracy + and performance. */ + if (PyInt_Check(base)) { + if (PyInt_AsLong(base) == 10) { + return loghelper(arg, log10, "log"); + } + else + PyErr_Clear(); + } + else if (PyLong_Check(base)) { + if (PyLong_AsLong(base) == 10) { + return loghelper(arg, log10, "log"); + } + else + PyErr_Clear(); + } + else if (PyFloat_Check(base)) { + if (PyFloat_AsDouble(base) == 10.0) { + return loghelper(arg, log10, "log"); + } + else + PyErr_Clear(); + } + den = loghelper(base, log, "log"); if (den == NULL) { Py_DECREF(num);