| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 5e6661b commit 68b2e42
2 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -324,6 +324,7 @@ def testAtan2(self): | |||
| 324 | 324 | self.ftest('atan2(0, 1)', math.atan2(0, 1), 0) | |
| 325 | 325 | self.ftest('atan2(1, 1)', math.atan2(1, 1), math.pi/4) | |
| 326 | 326 | self.ftest('atan2(1, 0)', math.atan2(1, 0), math.pi/2) | |
| 327 | + self.ftest('atan2(1, -1)', math.atan2(1, -1), 3*math.pi/4) | ||
| 327 | 328 | ||
| 328 | 329 | # math.atan2(0, x) | |
| 329 | 330 | self.ftest('atan2(0., -inf)', math.atan2(0., NINF), math.pi) | |
@@ -598,6 +599,7 @@ def testFmod(self): | |||
| 598 | 599 | self.assertEqual(math.fmod(-3.0, NINF), -3.0) | |
| 599 | 600 | self.assertEqual(math.fmod(0.0, 3.0), 0.0) | |
| 600 | 601 | self.assertEqual(math.fmod(0.0, NINF), 0.0) | |
| 602 | + self.assertRaises(ValueError, math.fmod, INF, INF) | ||
| 601 | 603 | ||
| 602 | 604 | def testFrexp(self): | |
| 603 | 605 | self.assertRaises(TypeError, math.frexp) | |
@@ -714,6 +716,11 @@ def msum(iterable): | |||
| 714 | 716 | s = msum(vals) | |
| 715 | 717 | self.assertEqual(msum(vals), math.fsum(vals)) | |
| 716 | 718 | ||
| 719 | + self.assertEqual(math.fsum([1.0, math.inf]), math.inf) | ||
| 720 | + self.assertRaises(OverflowError, math.fsum, [1e+308, 1e+308]) | ||
| 721 | + self.assertRaises(ValueError, math.fsum, [math.inf, -math.inf]) | ||
| 722 | + self.assertRaises(TypeError, math.fsum, ['spam']) | ||
| 723 | + | ||
| 717 | 724 | def testGcd(self): | |
| 718 | 725 | gcd = math.gcd | |
| 719 | 726 | self.assertEqual(gcd(0, 0), 0) | |
@@ -831,6 +838,8 @@ def testHypot(self): | |||
| 831 | 838 | scale = FLOAT_MIN / 2.0 ** exp | |
| 832 | 839 | self.assertEqual(math.hypot(4*scale, 3*scale), 5*scale) | |
| 833 | 840 | ||
| 841 | + self.assertRaises(TypeError, math.hypot, *([1.0]*18), 'spam') | ||
| 842 | + | ||
| 834 | 843 | @requires_IEEE_754 | |
| 835 | 844 | @unittest.skipIf(HAVE_DOUBLE_ROUNDING, | |
| 836 | 845 | "hypot() loses accuracy on machines with double rounding") | |
@@ -966,13 +975,19 @@ class T(tuple): | |||
| 966 | 975 | dist((1, 2, 3, 4), (5, 6, 7)) | |
| 967 | 976 | with self.assertRaises(ValueError): # Check dimension agree | |
| 968 | 977 | dist((1, 2, 3), (4, 5, 6, 7)) | |
| 978 | + with self.assertRaises(TypeError): | ||
| 979 | + dist((1,)*17 + ("spam",), (1,)*18) | ||
| 969 | 980 | with self.assertRaises(TypeError): # Rejects invalid types | |
| 970 | 981 | dist("abc", "xyz") | |
| 971 | 982 | int_too_big_for_float = 10 ** (sys.float_info.max_10_exp + 5) | |
| 972 | 983 | with self.assertRaises((ValueError, OverflowError)): | |
| 973 | 984 | dist((1, int_too_big_for_float), (2, 3)) | |
| 974 | 985 | with self.assertRaises((ValueError, OverflowError)): | |
| 975 | 986 | dist((2, 3), (1, int_too_big_for_float)) | |
| 987 | + with self.assertRaises(TypeError): | ||
| 988 | + dist((1,), 2) | ||
| 989 | + with self.assertRaises(TypeError): | ||
| 990 | + dist([1], 2) | ||
| 976 | 991 | ||
| 977 | 992 | # Verify that the one dimensional case is equivalent to abs() | |
| 978 | 993 | for i in range(20): | |
@@ -1111,6 +1126,7 @@ def test_lcm(self): | |||
| 1111 | 1126 | ||
| 1112 | 1127 | def testLdexp(self): | |
| 1113 | 1128 | self.assertRaises(TypeError, math.ldexp) | |
| 1129 | + self.assertRaises(TypeError, math.ldexp, 2.0, 1.1) | ||
| 1114 | 1130 | self.ftest('ldexp(0,1)', math.ldexp(0,1), 0) | |
| 1115 | 1131 | self.ftest('ldexp(1,1)', math.ldexp(1,1), 2) | |
| 1116 | 1132 | self.ftest('ldexp(1,-1)', math.ldexp(1,-1), 0.5) | |
@@ -1153,6 +1169,7 @@ def testLog(self): | |||
| 1153 | 1169 | 2302.5850929940457) | |
| 1154 | 1170 | self.assertRaises(ValueError, math.log, -1.5) | |
| 1155 | 1171 | self.assertRaises(ValueError, math.log, -10**1000) | |
| 1172 | + self.assertRaises(ValueError, math.log, 10, -10) | ||
| 1156 | 1173 | self.assertRaises(ValueError, math.log, NINF) | |
| 1157 | 1174 | self.assertEqual(math.log(INF), INF) | |
| 1158 | 1175 | self.assertTrue(math.isnan(math.log(NAN))) | |
@@ -2364,6 +2381,14 @@ def __float__(self): | |||
| 2364 | 2381 | # argument to a float. | |
| 2365 | 2382 | self.assertFalse(getattr(y, "converted", False)) | |
| 2366 | 2383 | ||
| 2384 | + def test_input_exceptions(self): | ||
| 2385 | + self.assertRaises(TypeError, math.exp, "spam") | ||
| 2386 | + self.assertRaises(TypeError, math.erf, "spam") | ||
| 2387 | + self.assertRaises(TypeError, math.atan2, "spam", 1.0) | ||
| 2388 | + self.assertRaises(TypeError, math.atan2, 1.0, "spam") | ||
| 2389 | + self.assertRaises(TypeError, math.atan2, 1.0) | ||
| 2390 | + self.assertRaises(TypeError, math.atan2, 1.0, 2.0, 3.0) | ||
| 2391 | + | ||
| 2367 | 2392 | # Custom assertions. | |
| 2368 | 2393 | ||
| 2369 | 2394 | def assertIsNaN(self, value): | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1219,13 +1219,7 @@ static PyObject * | |||
| 1219 | 1219 | math_floor(PyObject *module, PyObject *number) | |
| 1220 | 1220 | /*[clinic end generated code: output=c6a65c4884884b8a input=63af6b5d7ebcc3d6]*/ | |
| 1221 | 1221 | { | |
| 1222 | - double x; | ||
| 1223 | - | ||
| 1224 | - if (PyFloat_CheckExact(number)) { | ||
| 1225 | - x = PyFloat_AS_DOUBLE(number); | ||
| 1226 | - } | ||
| 1227 | - else | ||
| 1228 | - { | ||
| 1222 | + if (!PyFloat_CheckExact(number)) { | ||
| 1229 | 1223 | math_module_state *state = get_math_module_state(module); | |
| 1230 | 1224 | PyObject *method = _PyObject_LookupSpecial(number, state->str___floor__); | |
| 1231 | 1225 | if (method != NULL) { | |
@@ -1235,10 +1229,11 @@ math_floor(PyObject *module, PyObject *number) | |||
| 1235 | 1229 | } | |
| 1236 | 1230 | if (PyErr_Occurred()) | |
| 1237 | 1231 | return NULL; | |
| 1238 | - x = PyFloat_AsDouble(number); | ||
| 1239 | - if (x == -1.0 && PyErr_Occurred()) | ||
| 1240 | - return NULL; | ||
| 1241 | 1232 | } | |
| 1233 | + double x = PyFloat_AsDouble(number); | ||
| 1234 | + if (x == -1.0 && PyErr_Occurred()) | ||
| 1235 | + return NULL; | ||
| 1236 | + | ||
| 1242 | 1237 | return PyLong_FromDouble(floor(x)); | |
| 1243 | 1238 | } | |
| 1244 | 1239 | ||
@@ -2223,12 +2218,10 @@ math_modf_impl(PyObject *module, double x) | |||
| 2223 | 2218 | double y; | |
| 2224 | 2219 | /* some platforms don't do the right thing for NaNs and | |
| 2225 | 2220 | infinities, so we take care of special cases directly. */ | |
| 2226 | - if (!Py_IS_FINITE(x)) { | ||
| 2227 | - if (Py_IS_INFINITY(x)) | ||
| 2228 | - return Py_BuildValue("(dd)", copysign(0., x), x); | ||
| 2229 | - else if (Py_IS_NAN(x)) | ||
| 2230 | - return Py_BuildValue("(dd)", x, x); | ||
| 2231 | - } | ||
| 2221 | + if (Py_IS_INFINITY(x)) | ||
| 2222 | + return Py_BuildValue("(dd)", copysign(0., x), x); | ||
| 2223 | + else if (Py_IS_NAN(x)) | ||
| 2224 | + return Py_BuildValue("(dd)", x, x); | ||
| 2232 | 2225 | ||
| 2233 | 2226 | errno = 0; | |
| 2234 | 2227 | x = modf(x, &y); | |
@@ -2985,7 +2978,7 @@ math_pow_impl(PyObject *module, double x, double y) | |||
| 2985 | 2978 | else /* y < 0. */ | |
| 2986 | 2979 | r = odd_y ? copysign(0., x) : 0.; | |
| 2987 | 2980 | } | |
| 2988 | - else if (Py_IS_INFINITY(y)) { | ||
| 2981 | + else { /* Py_IS_INFINITY(y) */ | ||
| 2989 | 2982 | if (fabs(x) == 1.0) | |
| 2990 | 2983 | r = 1.; | |
| 2991 | 2984 | else if (y > 0. && fabs(x) > 1.0) | |
@@ -3515,10 +3508,6 @@ static const uint8_t factorial_trailing_zeros[] = { | |||
| 3515 | 3508 | static PyObject * | |
| 3516 | 3509 | perm_comb_small(unsigned long long n, unsigned long long k, int iscomb) | |
| 3517 | 3510 | { | |
| 3518 | - if (k == 0) { | ||
| 3519 | - return PyLong_FromLong(1); | ||
| 3520 | - } | ||
| 3521 | - | ||
| 3522 | 3511 | /* For small enough n and k the result fits in the 64-bit range and can | |
| 3523 | 3512 | * be calculated without allocating intermediate PyLong objects. */ | |
| 3524 | 3513 | if (iscomb) { | |
| Back | FazBrowse Home | New Git URL |
0 commit comments