[Jython-checkins] jython: Raise ValueError on args of invalid domain for math.sqrt, math.log to
jim.baker
jython-checkins at python.org
Tue May 13 15:59:18 CEST 2014
http://hg.python.org/jython/rev/a5b000944a51
changeset: 7244:a5b000944a51
user: Santoso Wijaya <santoso.wijaya at gmail.com>
date: Tue May 13 09:41:50 2014 -0400
summary:
Raise ValueError on args of invalid domain for math.sqrt, math.log to
conform to CPython. Fixes #2140.
files:
ACKNOWLEDGMENTS | 1 +
Lib/test/test_math_jy.py | 9 +++++++++
src/org/python/modules/math.java | 4 ++--
3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS
--- a/ACKNOWLEDGMENTS
+++ b/ACKNOWLEDGMENTS
@@ -106,6 +106,7 @@
Brandon Pedersen
Chris Simpson
Indra Talip
+ Michael Büsch
Local Variables:
mode: indented-text
diff --git a/Lib/test/test_math_jy.py b/Lib/test/test_math_jy.py
--- a/Lib/test/test_math_jy.py
+++ b/Lib/test/test_math_jy.py
@@ -28,6 +28,15 @@
self.assertEqual(inf, math.hypot(ninf, 4))
self.assertEqual(inf, math.hypot(4, ninf))
+ def test_math_domain_error(self):
+ self.assertRaises(ValueError, math.sqrt, -1)
+ self.assertRaises(ValueError, math.sqrt, -1.5)
+ self.assertRaises(ValueError, math.sqrt, -0.5)
+ self.assertRaises(ValueError, math.log, 0)
+ self.assertRaises(ValueError, math.log, -1)
+ self.assertRaises(ValueError, math.log, -1.5)
+ self.assertRaises(ValueError, math.log, -0.5)
+
def test_main():
test_support.run_unittest(MathTestCase)
diff --git a/src/org/python/modules/math.java b/src/org/python/modules/math.java
--- a/src/org/python/modules/math.java
+++ b/src/org/python/modules/math.java
@@ -318,7 +318,7 @@
if (ispinf(v)) {
return v;
}
- if (isninf(v) || v == MINUS_ONE) {
+ if (isninf(v) || v < MINUS_ZERO) {
throwMathDomainValueError();
}
return Math.sqrt(v);
@@ -545,7 +545,7 @@
}
private static double log(double v) {
- if (isninf(v)) {
+ if (isninf(v) || v <= ZERO) {
throwMathDomainValueError();
}
if (isinf(v) || isnan(v)) {
--
Repository URL: http://hg.python.org/jython
More information about the Jython-checkins
mailing list